Memory leak on DeathMonitor with LeakCanary
I am using LeakCanary and unfortunately got leaked and here is the logcat:
In com.appturbo.appoftheday2015:2.09.2:222.
* com.appturbo.appturbo.ui.HomeActivity has leaked:
* GC ROOT com.android.internal.util.AsyncChannel$DeathMonitor.this$0
* references com.android.internal.util.AsyncChannel.mSrcContext
* leaks com.appturbo.appturbo.ui.HomeActivity instance
* Reference Key: e049c2ed-6784-4850-b794-20fa96c13dcf
* Device: motorola google Nexus 6 shamu
* Android Version: 5.1 API: 22
* Durations: watch=5176ms, gc=228ms, heap dump=4974ms, analysis=29320ms
Have some of you already seen such a leak? Any ideas? This leak appears after:
- Change resource configuration for language switching
- Completion of work
- Restarting activity
+3
source to share
1 answer
After digging in some wrong memory search. I found a solution to this memory leak. The problem is that some pushes are not properly separated from the view and keep a pointer to some other object. Because of this, the GC is unable to remove these objects, and here is our memory leak.
To solve this problem, I use this code to reverse checkout.
public static void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
+1
source to share