-
Notifications
You must be signed in to change notification settings - Fork 840
Memory leak in ViewGroupMviDelegateImpl #310
Description
Hello!
I found a memory leak in ViewGroupMviDelegateImpl.
Mosby version is 3.1.0.
Steps to reproduce:
- create
CustomViewextendingMviFrameLayoutorMviLinearLayoutorMviRelativeLayout - programmaticaly add this
CustomViewto view hierarchy while activity is resumed - programmaticaly remove this
CustomViewfrom view hierarchy while activity is resumed
After that CustomView will be in memory until activity is destroyed.
I also found that this is because of registering ActivityLifecycleCallbacks when creating ViewGroupMviDelegateImpl.
ViewGroupMviDelegateImpl removes ActivityLifecycleCallbacks only when activity is destroyed. But there may be a lot of such CustomView those will hang in memory though they are detached and removed from view hierarchy.
I reviewed logic of consuming activity-lifecycle in ViewGroupMviDelegateImpl and may be we can register ActivityLifecycleCallbacks when attaching view to presenter and unregister ActivityLifecycleCallbacks in two cases: when activity is destroying and also when detaching view from presenter ?