From 7abdfa72e372d927bf2dec3185e05588cb1a94b7 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 19 Jan 2018 13:14:38 +0100 Subject: #8822 adds leakCanary library to Bitmask for analyzing memory leaks --- .../java/se/leap/bitmaskclient/BitmaskApp.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java b/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java index 88a01b62..f9e45b79 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java +++ b/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java @@ -1,6 +1,10 @@ package se.leap.bitmaskclient; import android.app.Application; +import android.content.Context; + +import com.squareup.leakcanary.LeakCanary; +import com.squareup.leakcanary.RefWatcher; /** * Created by cyberta on 24.10.17. @@ -8,11 +12,31 @@ import android.app.Application; public class BitmaskApp extends Application { + private RefWatcher refWatcher; + @Override public void onCreate() { super.onCreate(); + if (LeakCanary.isInAnalyzerProcess(this)) { + // This process is dedicated to LeakCanary for heap analysis. + // You should not init your app in this process. + return; + } + refWatcher = LeakCanary.install(this); + // Normal app init code...*/ PRNGFixes.apply(); - //TODO: add LeakCanary! } + /** + * Use this method to get a RefWatcher object that checks for memory leaks in the given context. + * Call refWatcher.watch(this) to check if all references get garbage collected. + * @param context + * @return the RefWatcher object + */ + public static RefWatcher getRefWatcher(Context context) { + BitmaskApp application = (BitmaskApp) context.getApplicationContext(); + return application.refWatcher; + } + + } -- cgit v1.2.3