Leak tree always shows only single item pointing to application class
Opened this issue · 4 comments
I appreciate you working on this, as I really miss LeakCanary since I moved to Xamarin Android.
However, it seems that there is something wrong with the leak notifications, as for every activity/fragment, I get something like the following notification:
There is never a real memory tree, only one single object that points to the main app. (Clicking the + Icon does not change this)
I think there are only two possibilities here:
- There is no leak, but the notification shows up anyway
- There is a memory leak, but the retrival of the memory tree is somehow not working or incomplete.
Any thoughts?
Tested on
- Emulator (Nexux 9, API 23)
- Nexus 5 (Android 6.0)
- Pixel XL (Anroid 8.1 - side note: notifications don't show up BTW, most likely because the app didn't register a proper notification channel as required on API 26+)
Hi
I think it is possible that this behavior is a false positive. The problem is that you have the Xamarin GC on one side and the Dalvik GC on the other side (both must work together).
The Dalvik GC does not know anything about the Xamarin GC and can not clean up any resources that are hold by an object in the Xamarin world (a JNI global reference is treated as a GC root).
Therefore, it is required that the Xamarin GC is triggered before LeakCanary can properly analyze the object tree for memory leaks.
You can test this with a customized refWatcher that will call the Xamarin GC after an activity is destroyed.
There is a good SO answer for more details about the Xamarin GC. It is a pity that this documentation is not available on the public Xamarin website but only in the Xamarin University.
I too love LeakCanary and glad that you have ported it for Xamarin. But I am also experiencing the same output as @Dan1ve . Can you help me out with creating customized refWatcher that shows proper memory leak trace. I am afraid, maybe using this binding is not fruitful for Xamarin.Android. Need your guidance. Thanks !
@Dan1ve were you able to find anything ?
@raj-gogri unfortunately, I couldn't get this to work :/ I tried to call GC.Minor() in the OnDestroy() methods, but the false positives still occurred