Let's say I have an Flowable that is shared among different parts of the application.
In each fragment where I want to observe it, I convert it to a LiveData with LiveDataReactiveStreams.fromPublisher
to avoid leaks and crashes. I now have a LiveData that wraps my Flowable.
I then pass the LiveData to my ViewModel (in the ViewModelFactory). As far as I understand, I can go ahead and use the LiveData without worrying about leaks.
Now, instead of observing the LiveData directly, I am tempted to convert it back to a Flowable with LiveDataReactiveStreams.toPublisher
and Flowable.fromPublisher
and subscribe to the Flowable instead. This is now a Flowable that wraps a LiveData which wraps a Flowable
My question is: Do I have to worry about disposing the subscriptions to this Flowable? My hope is that the LiveData will act as a "barrier", preventing my context to leak back up to the root Flowable, but I am not so sure about that.
In other words:
- Flowable A exists in a global context
- In each fragment, A is wrapped in LiveData B which is set as a property of the fragments ViewModel
- When normally I would observe LiveData B, I instead wrap it in Flowable C
- I subscribe to Flowable C and ignore the returned disposable
Will views accessed in C leak up to A when the fragment is destroyed?