How to handle memory leaks?
The Activity starts to change configurations — is mercilessly torn down and recreated — but the previously existing and held reference keeps the Activity context and all its inflated Views alive, the garbage collector cannot finalize them. Of course, this also applies if the Activity is registered to a global bus, but it’s never unregistered, and the Activity is finished. Also happens if there is an uncleared static reference to the Activity. All of these can cause a memory leak.
Effective remedies to be used
- WeakReference
- Using an EventBus that is paused while the Activity is not resumed, and enqueues events while paused
- PublishRelay + ObservableTransformers.valve()
- LiveData
Read more about possible solutions here
Comments
Post a Comment