Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about using RxBinding + VM #503

Open
desgraci opened this issue Feb 23, 2019 · 1 comment
Open

Question about using RxBinding + VM #503

desgraci opened this issue Feb 23, 2019 · 1 comment

Comments

@desgraci
Copy link

desgraci commented Feb 23, 2019

It is a good idea to have a RxBinding Observable passed to my VM, apply the business logic, then add to the VM disposable bag, and subscribing to that Observable on the Activity/Fragment?

Just wondering, since I have some Business logic on the VM for processing the input, but in theory I'm sending a reference of the view to the VM, which sounds, not that great, also there is a weird going back and forth that I don't personally like, how you guys think it would be best handled this cases?

@alexsullivan114
Copy link

If you pass an RxBInding observable into an android ViewModel and only dispose in the ViewModels onCleared method you'll end up leaking the activity, since the observable keeps a strong reference to the activity.

Here's a sample repository that uses LeakCanary to listen for leaks. If you run the app and rotate the screen and wait a few moments you'll see LeakCanary make some noise about a leaked activity.

From what I can tell the best option is to create a PublishSubject and subscribe to the observable produced via RxBInding in your Activity/Fragment and forward the passed through data to that PublishSubject. You can then dispose of the observable created in your Activity/Fragment.

This isn't a particularly satisfactory approach so I'm very open to any other suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants