This is a Xamarin.Android Binding for the Square.LeakCanary library. A memory leak detection library for Android and Java.
“A small leak will sink a great ship.” - Benjamin Franklin
In your Application
class:
[Application]
internal class MainApplication : Application
{
private RefWatcher _refWatcher;
protected MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public override void OnCreate()
{
base.OnCreate();
SetupLeakCanary();
}
protected void SetupLeakCanary()
{
if (LeakCanaryXamarin.IsInAnalyzerProcess(this))
{
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
_refWatcher = LeakCanaryXamarin.Install(this);
}
}
You're good to go! LeakCanary will automatically show a notification when an activity memory leak is detected in your debug build.
Questions? Check out the official LeakCanary FAQ!
To customize LeakCanary, see the wiki of LeakCanary.
Unfortunately, there is a bug in Xamarin.Android, which does not allow to have a custom Application
class and a Service
running within an isolated process. Therefore it was required to use a modified version of the LeakCanaray library for the binding to work.