```fun Disposable.disposeOnDestroy(lifecycleOwner:...
# codereview
a
Copy code
fun Disposable.disposeOnDestroy(lifecycleOwner: LifecycleOwner) {
    lifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
        override fun onDestroy(owner: LifecycleOwner) {
            this@disposeOnDestroy.dispose()
        }
    })
}

// usage
updateBasicInfo().subscribe() {
   //...
   onSubscribe {
      it.attachToLifecycle(viewLifecycleOwner)
   }
}
I wrote this extension for disposing subscriptions. I know it might seems stupid but my actual concern is object leak.
updateBasicInfo
creates a new observable and it call an web API. does
DefaultLifecycleObserver
keep the Disposable (observable) reference, even when the observable has been completed?