/LeakCanaryBinding

Xamarin.Android Binding for Square.LeakCanary

Primary LanguageC#Apache License 2.0Apache-2.0

nuget link

LeakCanaryBinding

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

screenshot

Getting started

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!

Customizing LeakCanary

To customize LeakCanary, see the wiki of LeakCanary.

LeakCanary Modifications for Xamarin

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.