smallseo.info

leakcanary

A memory leak detection library for Android and Java.

NullPointerException from LeakCanary when running Robolectric tests

Added LeakCanary (1.3) to my Application:

@Override
public void onCreate() {
    super.onCreate();
    Fabric.with(this, new Crashlytics());
    LeakCanary.install(this);

When I run the Robolectric test suite for my application I get a NullPointerException in LeakCanary.

Caused by: java.lang.NullPointerException
at com.squareup.leakcanary.LeakCanary.isInServiceProcess(LeakCanary.java:165)
at com.squareup.leakcanary.LeakCanary.isInAnalyzerProcess(LeakCanary.java:141)
at com.squareup.leakcanary.LeakCanary.install(LeakCanary.java:52)
at com.squareup.leakcanary.LeakCanary.install(LeakCanary.java:43)
at com.package.application.MyApplication.onCreate(MyApplication.java:50)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:131)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:431)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:224)

I added that Im using Crashlytics to point out that it (and other methods as well) receives the same Application but does not throw any Exceptions.

Wasn't sure if this should be here or on GitHub issues for LeakCanary. Anyone else experiencing this issue?


Source: (StackOverflow)

Why is this a memory leak

I came across a library for memory leak detection in Android (Java) called LeakCanary but cannot understand the example where they leak the memory. Could anybody please explain how and why the code shown in their example is a memory leak.

class Cat {
}
class Box {
  Cat hiddenCat;
}
class Docker {
  static Box container;
}

// ...

Box box = new Box();
Cat schrodingerCat = new Cat();
box.hiddenCat = schrodingerCat;
Docker.container = box;

and then they watch the variable schrodingerCat for leaks which gives a leak shown as follows (which I dont know how to relate to the above code).

* GC ROOT static Docker.container
* references Box.hiddenCat
* leaks Cat instance

Any help with the explanation of the leak and how the detection relates to it would be very helpful. Also some good articles for beginners would be nice.

Thanks!


Source: (StackOverflow)

Android memory leak on textview - LeakCanary (Leak can be ignored)

I keep having the following memory leak as displayed by LeakCanary, when I go from my splash screen to the mainactivity. I understand that this is an expected leak due to fault in the Android OS itself, but is there a way I can avoid this (by setting specifics of some TextView somewhere?)

05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * LEAK CAN BE IGNORED.
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * com.gmspartnersltd.earthmiles.views.ActivitySignUp_ has leaked:
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * GC ROOT static android.text.TextLine.sCached
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * references array android.text.TextLine[].[1]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * references android.text.TextLine.mCharacterStyleSpanSet
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * references android.text.SpanSet.spans
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * references array android.text.style.CharacterStyle[].[1]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * references com.gmspartnersltd.earthmiles.views.ActivitySignUp$2.this$0 (anonymous class extends android.text.style.ClickableSpan)
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * leaks com.gmspartnersltd.earthmiles.views.ActivitySignUp_ instance
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ [ 05-22 08:54:52.160 13969:18091 D/LeakCanary ]
    * Reference Key: bb8124a9-2829-4ff3-8ded-13cf35f80f54
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Device: Genymotion generic Google Nexus 5 - 5.0.0 - API 21 - 1080x1920 vbox86p
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Android Version: 5.0 API: 21 LeakCanary: 1.3.1
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Durations: watch=10898ms, gc=137ms, heap dump=5529ms, analysis=9193ms
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ [ 05-22 08:54:52.160 13969:18091 D/LeakCanary ]
    * Details:
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Class android.text.TextLine
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static $staticOverhead = byte[] [id=0x70622169;length=24;size=40]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static sCached = android.text.TextLine[] [id=0x70775010;length=3]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static DEBUG = false
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static TAB_INCREMENT = 20
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Array of android.text.TextLine[]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   [0] = android.text.TextLine [id=0x1309a2e0]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   [1] = android.text.TextLine [id=0x12eed650]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   [2] = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Instance of android.text.TextLine
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static $staticOverhead = byte[] [id=0x70622169;length=24;size=40]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static sCached = android.text.TextLine[] [id=0x70775010;length=3]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static DEBUG = false
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   static TAB_INCREMENT = 20
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCharacterStyleSpanSet = android.text.SpanSet [id=0x12e32d80]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mChars = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDirections = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mMetricAffectingSpanSpanSet = android.text.SpanSet [id=0x12e32d60]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mPaint = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mReplacementSpanSpanSet = android.text.SpanSet [id=0x12e32da0]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mSpanned = android.text.SpannedString [id=0x132dabe0]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTabs = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mText = null
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mWorkPaint = android.text.TextPaint [id=0x1300f5c0]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCharsValid = false
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDir = 1
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mHasTabs = false
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLen = 1
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mStart = 0
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Instance of android.text.SpanSet
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   classType = java.lang.Class [id=0x703bb448;name=android.text.style.CharacterStyle]
05-22 08:54:52.160  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   spanEnds = int[] [id=0x1309fd60;length=2;size=24]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   spanFlags = int[] [id=0x1309fda0;length=2;size=24]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   spanStarts = int[] [id=0x1309fd20;length=2;size=24]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   spans = android.text.style.CharacterStyle[] [id=0x1309fce0;length=2]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   numberOfSpans = 1
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Array of android.text.style.CharacterStyle[]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   [0] = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   [1] = com.gmspartnersltd.earthmiles.views.ActivitySignUp$2 [id=0x130952c0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Instance of com.gmspartnersltd.earthmiles.views.ActivitySignUp$2
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   this$0 = com.gmspartnersltd.earthmiles.views.ActivitySignUp_ [id=0x13361800]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ * Instance of com.gmspartnersltd.earthmiles.views.ActivitySignUp_
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   onViewChangedNotifier_ = org.androidannotations.api.view.OnViewChangedNotifier [id=0x13052dc0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   birthday = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   buttonNext = android.support.v7.widget.AppCompatButton [id=0x13459c00]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   confirmPassword = java.lang.String [id=0x132f01a0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   editTextConformPassword = android.support.v7.widget.AppCompatEditText [id=0x13458400]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   editTextEmail = android.support.v7.widget.AppCompatEditText [id=0x1339b000]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   editTextFirstName = android.support.v7.widget.AppCompatEditText [id=0x13396c00]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   editTextLastName = android.support.v7.widget.AppCompatEditText [id=0x13398800]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   editTextPassword = android.support.v7.widget.AppCompatEditText [id=0x13456c00]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   email = java.lang.String [id=0x132f0040]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   facebook = com.facebook.android.Facebook [id=0x1307ee00]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   fbUserId = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   firstName = java.lang.String [id=0x132f0080]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   gender = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   lastName = java.lang.String [id=0x132f00e0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   location = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mAsyncRunner = com.facebook.android.AsyncFacebookRunner [id=0x130952a0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   password = java.lang.String [id=0x132f0140]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   termsOfUse = android.support.v7.widget.AppCompatTextView [id=0x1345a000]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   text = android.text.SpannableString [id=0x1310eaa0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   fromFacebook = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   etHelpMessage = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mProgressHUD = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   positiveAction = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   showBusyAnimationRequesterCount = 0
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDelegate = android.support.v7.app.AppCompatDelegateImplV11 [id=0x12ecfd80]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mAllLoaderManagers = android.support.v4.util.SimpleArrayMap [id=0x131d80a0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mContainer = android.support.v4.app.FragmentActivity$2 [id=0x13052db0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mFragments = android.support.v4.app.FragmentManagerImpl [id=0x12f7cf60]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mHandler = android.support.v4.app.FragmentActivity$1 [id=0x1310ea80]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLoaderManager = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCheckedForLoaderManager = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCreated = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLoadersStarted = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mOptionsMenuInvalidated = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mReallyStopped = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mResumed = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mRetaining = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mStopped = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mActionBar = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mActivityInfo = android.content.pm.ActivityInfo [id=0x12db0180]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mActivityTransitionState = android.app.ActivityTransitionState [id=0x1304b600]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mAllLoaderManagers = android.util.ArrayMap [id=0x131c9d00]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mApplication = com.gmspartnersltd.earthmiles.globalstate.App [id=0x12c6e8c0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mComponent = android.content.ComponentName [id=0x12f64150]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mContainer = android.app.Activity$1 [id=0x13052d70]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCurrentConfig = android.content.res.Configuration [id=0x12f97520]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDecor = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDefaultKeySsb = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mEmbeddedID = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mEnterTransitionListener = android.app.SharedElementCallback$1 [id=0x70765ba8]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mExitTransitionListener = android.app.SharedElementCallback$1 [id=0x70765ba8]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mFragments = android.app.FragmentManagerImpl [id=0x12f7cef0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mHandler = android.os.Handler [id=0x1310ea60]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mInstanceTracker = android.os.StrictMode$InstanceTracker [id=0x13052d90]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mInstrumentation = android.app.Instrumentation [id=0x12c33f70]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mIntent = android.content.Intent [id=0x12f3b300]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLastNonConfigurationInstances = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLoaderManager = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mMainThread = android.app.ActivityThread [id=0x12c2b100]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mManagedCursors = java.util.ArrayList [id=0x1310ea40]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mManagedDialogs = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mMenuInflater = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mParent = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mResultData = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mSearchManager = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTitle = java.lang.String [id=0x12e6d7e0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mToken = android.os.BinderProxy [id=0x12fe86a0]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTranslucentCallback = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mUiThread = java.lang.Thread [id=0x73b43540]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mVoiceInteractor = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mWindow = com.android.internal.policy.impl.PhoneWindow [id=0x12e5d580]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mWindowManager = android.view.WindowManagerImpl [id=0x1310ed20]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCalled = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mChangeCanvasToTranslucent = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mChangingConfigurations = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mCheckedForLoaderManager = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mConfigChangeFlags = 0
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDefaultKeyMode = 0
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDestroyed = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mDoReportFullyDrawn = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mEnableDefaultActionBarUp = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mFinished = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mIdent = 24993652
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mLoadersStarted = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mResultCode = 0
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mResumed = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mStartedActivity = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mStopped = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTemporaryPause = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTitleColor = 0
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTitleReady = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mVisibleBehind = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mVisibleFromClient = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mVisibleFromServer = false
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mWindowAdded = true
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mInflater = com.android.internal.policy.impl.PhoneLayoutInflater [id=0x13152580]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mOverrideConfiguration = null
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mResources = android.content.res.Resources [id=0x12c33f20]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mTheme = android.content.res.Resources$Theme [id=0x1310ed40]
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mThemeResource = 2131689670
05-22 08:54:52.161  13969-18091/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ |   mBase = android.app.ContextImpl [id=0x12c81100]

Source: (StackOverflow)

how to use leakcanary, how to add leakcanary as a jar to build a apk with .mk file

LeakCanary is a memory leak detection library for Android and Java. LeakCanary

My project is based on android make file system, which relies on some android internal interfaces and custom methods.

How can I add the LeakCanary as a lib into my app to detect memory leak.

My solution: First, I have to build the LeakCanary as a jar file, but how to. as it's a gradle directory structure, and I have never used Gradle before.

Any tip is precious.


Source: (StackOverflow)

Retained fragment leak

I'm using the simple activity with the retained fragment which holds some data used by the activity. The retained fragment uses the loader to get the data from a content provider. On configuration change (screen rotation) the activity is recreated and the old instance is leaked as reported by LeakCanary library (retained fragment -> loader manager -> old activity). This reproduced with the support-v4 23.0.0 library (and the previous versions also). The sample of the activity with the retained fragment where leak is reproduced (no useful code here, only to demonstrate the leak):

package com.leaksample;

import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private ModelFragment mModelFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FragmentManager fm = getSupportFragmentManager();
        mModelFragment = (ModelFragment) fm.findFragmentByTag(ModelFragment.TAG);
        if (mModelFragment == null) {
            mModelFragment = new ModelFragment();
            fm.beginTransaction()
                    .add(mModelFragment, ModelFragment.TAG)
                    .commit();
            fm.executePendingTransactions();
        }
    }

    public static class ModelFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
        private static final String TAG = ModelFragment.class.getSimpleName();

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setRetainInstance(true);
            getLoaderManager().initLoader(0, null, this);
        }

        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new CursorLoader(getActivity(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    new String[]{MediaStore.Images.Media.DATA}, null, null, null);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
        }
    }
}

The stack from LeakCanary:

08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ In com.leaksample:1.0:1.
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * com.leaksample.MainActivity has leaked:
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * GC ROOT thread java.lang.Thread.<Java Local> (named 'Binder_1')
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * references android.view.ViewRootImpl.mContext
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * references com.leaksample.MainActivity.mModelFragment
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * references com.leaksample.MainActivity$ModelFragment.mLoaderManager
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * references android.support.v4.app.LoaderManagerImpl.mHost
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * references android.support.v4.app.FragmentActivity$HostCallbacks.this$0
08-29 19:52:34.129  15271-16632/com.leaksample D/LeakCanary﹕ * leaks com.leaksample.MainActivity instance

Maybe I'm doing something wrong and forgot to call some close or release method? I think using the retained fragment with the loader is a common pattern and should not be memory leaks here.


Source: (StackOverflow)

Understanding ViewTreeObserver leak

I am using LeakCanary 1.3.1-SNAPSHOT. I found a leak concerning ViewTreeObserver.OnScrollChangedListener setup and I fixed it like in the following code:

  private ViewTreeObserver.OnScrollChangedListener scrollViewChangeListener;

  @Override protected void onFinishInflate() {
      super.onFinishInflate();
      ButterKnife.inject(this);
      scrollViewChangeListener = new ViewTreeObserver.OnScrollChangedListener() {
      @Override public void onScrollChanged() {
        EventDetailsView.this.onScrollChanged(scrollView.getScrollY());
      }
    };
      scrollView.getViewTreeObserver()
        .addOnScrollChangedListener(scrollViewChangeListener);
  }
  @Override public void onDetachedFromWindow() {
      super.onDetachedFromWindow();
      scrollView.getViewTreeObserver().removeOnScrollChangedListener(scrollViewChangeListener);
  }

However LeakCanary still report it as a leak, any idea why?

* com.couchsurfing.mobile.ui.events.detail.EventDetailsScreen$Presenter has leaked:
* GC ROOT android.view.inputmethod.InputMethodManager$1.this$0 (anonymous class extends com.android.internal.view.IInputMethodClient$Stub)
* references android.view.inputmethod.InputMethodManager.mCurRootView
* references com.android.internal.policy.impl.PhoneWindow$DecorView.mAttachInfo
* references android.view.View$AttachInfo.mTreeObserver
* references android.view.ViewTreeObserver.mOnScrollChangedListeners
* references android.view.ViewTreeObserver$CopyOnWriteArray.mData
* references java.util.ArrayList.array
* references array java.lang.Object[].[0]
* references com.couchsurfing.mobile.ui.events.detail.EventDetailsView$1.this$0 (anonymous class implements android.view.ViewTreeObserver$OnScrollChangedListener)
* references com.couchsurfing.mobile.ui.events.detail.EventDetailsView.presenter
* leaks com.couchsurfing.mobile.ui.events.detail.EventDetailsScreen$Presenter instance* Reference Key: 69d0a429-ae27-48fc-a8e0-033c920dd07c
* Device: LGE google Nexus 5 hammerhead
* Android Version: 5.1 API: 22 LeakCanary: 1.3.1-SNAPSHOT
* Durations: watch=5032ms, gc=165ms, heap dump=2932ms, analysis=29907ms* Details:
* Instance of android.view.inputmethod.InputMethodManager$1
|   this$0 = android.view.inputmethod.InputMethodManager [id=0x130239c0]
|   mDescriptor = java.lang.String [id=0x6f5e3f38]
|   mObject = -1601862176
|   mOwner = android.view.inputmethod.InputMethodManager$1 [id=0x13112da0]
* Instance of android.view.inputmethod.InputMethodManager
|   static $staticOverhead = byte[] [id=0x6fe25d29;length=240;size=256]
|   static CONTROL_START_INITIAL = 256
|   static CONTROL_WINDOW_FIRST = 4
|   static CONTROL_WINDOW_IS_TEXT_EDITOR = 2
|   static CONTROL_WINDOW_VIEW_HAS_FOCUS = 1
|   static DEBUG = false
|   static DISPATCH_HANDLED = 1
|   static DISPATCH_IN_PROGRESS = -1
|   static DISPATCH_NOT_HANDLED = 0
|   static HIDE_IMPLICIT_ONLY = 1
|   static HIDE_NOT_ALWAYS = 2
|   static INPUT_METHOD_NOT_RESPONDING_TIMEOUT = 2500
|   static MSG_BIND = 2
|   static MSG_DUMP = 1
|   static MSG_FLUSH_INPUT_EVENT = 7
|   static MSG_SEND_INPUT_EVENT = 5
|   static MSG_SET_ACTIVE = 4
|   static MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 9
|   static MSG_TIMEOUT_INPUT_EVENT = 6
|   static MSG_UNBIND = 3
|   static NOT_AN_ACTION_NOTIFICATION_SEQUENCE_NUMBER = -1
|   static PENDING_EVENT_COUNTER = java.lang.String [id=0x6f5bb948]
|   static REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE = 0
|   static RESULT_HIDDEN = 3
|   static RESULT_SHOWN = 2
|   static RESULT_UNCHANGED_HIDDEN = 1
|   static RESULT_UNCHANGED_SHOWN = 0
|   static SHOW_FORCED = 2
|   static SHOW_IMPLICIT = 1
|   static TAG = java.lang.String [id=0x6f5a76e0]
|   static sInstance = android.view.inputmethod.InputMethodManager [id=0x130239c0]
|   mActive = true
|   mBindSequence = 1523
|   mClient = android.view.inputmethod.InputMethodManager$1 [id=0x13112da0]
|   mCompletions = null
|   mCurChannel = android.view.InputChannel [id=0x1304a850]
|   mCurId = java.lang.String [id=0x1325dd80]
|   mCurMethod = com.android.internal.view.IInputMethodSession$Stub$Proxy [id=0x1304a840]
|   mCurRootView = com.android.internal.policy.impl.PhoneWindow$DecorView [id=0x12eac000]
|   mCurSender = android.view.inputmethod.InputMethodManager$ImeInputEventSender [id=0x12c72850]
|   mCurrentTextBoxAttribute = android.view.inputmethod.EditorInfo [id=0x133036c0]
|   mCursorAnchorInfo = null
|   mCursorCandEnd = 0
|   mCursorCandStart = 0
|   mCursorRect = android.graphics.Rect [id=0x13112d40]
|   mCursorSelEnd = 0
|   mCursorSelStart = 0
|   mDummyInputConnection = android.view.inputmethod.BaseInputConnection [id=0x13112dc0]
|   mFullscreenMode = false
|   mH = android.view.inputmethod.InputMethodManager$H [id=0x13112de0]
|   mHasBeenInactive = false
|   mIInputContext = android.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper [id=0x13113310]
|   mLastSentUserActionNotificationSequenceNumber = -1
|   mMainLooper = android.os.Looper [id=0x12c76be0]
|   mNextServedView = com.couchsurfing.mobile.ui.drawer.DrawerView [id=0x131f8c00]
|   mNextUserActionNotificationSequenceNumber = 1
|   mPendingEventPool = android.util.Pools$SimplePool [id=0x13110fe0]
|   mPendingEvents = android.util.SparseArray [id=0x13112d80]
|   mRequestUpdateCursorAnchorInfoMonitorMode = 0
|   mServedConnecting = false
|   mServedInputConnection = null
|   mServedInputConnectionWrapper = null
|   mServedView = com.couchsurfing.mobile.ui.drawer.DrawerView [id=0x131f8c00]
|   mService = com.android.internal.view.IInputMethodManager$Stub$Proxy [id=0x13110fc0]
|   mTmpCursorRect = android.graphics.Rect [id=0x13112d20]
|   mViewToScreenMatrix = android.graphics.Matrix [id=0x13110fd0]
|   mViewTopLeft = int[] [id=0x13112d60;length=2;size=24]
* Instance of com.android.internal.policy.impl.PhoneWindow$DecorView
|   mActionMode = null
|   mActionModePopup = null
|   mActionModeView = null
|   mBackgroundFallback = com.android.internal.widget.BackgroundFallback [id=0x12fdd8e0]
|   mBackgroundPadding = android.graphics.Rect [id=0x12ffd9a0]
|   mBarEnterExitDuration = 250
|   mChanging = false
|   mDefaultOpacity = -1
|   mDownY = 0
|   mDrawingBounds = android.graphics.Rect [id=0x12ffd980]
|   mFeatureId = -1
|   mFrameOffsets = android.graphics.Rect [id=0x12ffd9e0]
|   mFramePadding = android.graphics.Rect [id=0x12ffd9c0]
|   mHideInterpolator = android.view.animation.PathInterpolator [id=0x12ffdb00]
|   mLastBottomInset = 144
|   mLastHasBottomStableInset = true
|   mLastHasTopStableInset = true
|   mLastRightInset = 0
|   mLastTopInset = 75
|   mLastWindowFlags = -2122252032
|   mMenuBackground = null
|   mNavigationColorViewState = com.android.internal.policy.impl.PhoneWindow$ColorViewState [id=0x12ff2c70]
|   mNavigationGuard = null
|   mRootScrollY = 0
|   mShowActionModePopup = null
|   mShowInterpolator = android.view.animation.PathInterpolator [id=0x12ffda60]
|   mStatusColorViewState = com.android.internal.policy.impl.PhoneWindow$ColorViewState [id=0x12ff2c40]
|   mStatusGuard = null
|   mWatchingForMenu = false
|   this$0 = com.android.internal.policy.impl.PhoneWindow [id=0x12db9e00]
|   mForeground = null
|   mForegroundBoundsChanged = true
|   mForegroundGravity = 119
|   mForegroundInPadding = true
|   mForegroundPaddingBottom = 0
|   mForegroundPaddingLeft = 0
|   mForegroundPaddingRight = 0
|   mForegroundPaddingTop = 0
|   mForegroundTintList = null
|   mForegroundTintMode = null
|   mHasForegroundTint = false
|   mHasForegroundTintMode = false
|   mMatchParentChildren = java.util.ArrayList [id=0x12ffd960]
|   mMeasureAllChildren = false
|   mOverlayBounds = android.graphics.Rect [id=0x12ffd940]
|   mSelfBounds = android.graphics.Rect [id=0x12ffd920]
|   mAnimationListener = null
|   mCachePaint = null
|   mChildAcceptsDrag = false
|   mChildCountWithTransientState = 0
|   mChildTransformation = null
|   mChildren = android.view.View[] [id=0x130064c0;length=12]
|   mChildrenCount = 3
|   mCurrentDrag = null
|   mCurrentDragView = null
|   mDisappearingChildren = null
|   mDragNotifiedChildren = null
|   mFirstHoverTarget = null
|   mFirstTouchTarget = null
|   mFocused = android.widget.LinearLayout [id=0x12eac800]
|   mGroupFlags = 2375763
|   mHoveredSelf = false
|   mInvalidateRegion = null
|   mInvalidationTransformation = null
|   mLastTouchDownIndex = 0
|   mLastTouchDownTime = 137539724
|   mLastTouchDownX = 605.0
|   mLastTouchDownY = 1177.0
|   mLayoutAnimationController = null
|   mLayoutCalledWhileSuppressed = false
|   mLayoutMode = 0
|   mLayoutTransitionListener = android.view.ViewGroup$3 [id=0x12fdd850]
|   mLocalPoint = null
|   mNestedScrollAxes = 0
|   mOnHierarchyChangeListener = null
|   mPersistentDrawingCache = 2
|   mPreSortedChildren = null
|   mSuppressLayout = false
|   mTempPoint = float[] [id=0x12c0a220;length=2;size=24]
|   mTransition = null
|   mTransitioningViews = null
|   mVisibilityChangingChildren = null
|   mAccessibilityCursorPosition = -1
|   mAccessibilityDelegate = null
|   mAccessibilityTraversalAfterId = -1
|   mAccessibilityTraversalBeforeId = -1
|   mAccessibilityViewId = -1
|   mAnimator = null
|   mAttachInfo = android.view.View$AttachInfo [id=0x12c4fcc0]
|   mAttributes = null
|   mBackground = android.graphics.drawable.ColorDrawable [id=0x13014f80]
|   mBackgroundRenderNode = android.view.RenderNode [id=0x12c73740]
|   mBackgroundResource = 0
|   mBackgroundSizeChanged = false
|   mBackgroundTint = null
|   mBottom = 1920
|   mCachingFailed = false
|   mClipBounds = null
|   mContentDescription = null
|   mContext = com.couchsurfing.mobile.ui.MainActivity [id=0x12db9c80]
|   mCurrentAnimation = null
|   mDrawableState = null
|   mDrawingCache = null
|   mDrawingCacheBackgroundColor = 0
|   mFloatingTreeObserver = null
|   mGhostView = null
|   mHasPerformedLongPress = false
|   mID = -1
|   mInputEventConsistencyVerifier = null
|   mKeyedTags = null
|   mLabelForId = -1
|   mLastIsOpaque = true
|   mLayerPaint = null
|   mLayerType = 0
|   mLayoutInsets = null
|   mLayoutParams = android.view.WindowManager$LayoutParams [id=0x12f1f7e0]
|   mLeft = 0
|   mLeftPaddingDefined = true
|   mListenerInfo = android.view.View$ListenerInfo [id=0x13109940]
|   mMatchIdPredicate = null
|   mMatchLabelForPredicate = null
|   mMeasureCache = android.util.LongSparseLongArray [id=0x13400120]
|   mMeasuredHeight = 1920
|   mMeasuredWidth = 1080
|   mMinHeight = 0
|   mMinWidth = 0
|   mNestedScrollingParent = null
|   mNextFocusDownId = -1
|   mNextFocusForwardId = -1
|   mNextFocusLeftId = -1
|   mNextFocusRightId = -1
|   mNextFocusUpId = -1
|   mOldHeightMeasureSpec = 1073743744
|   mOldWidthMeasureSpec = 1073742904
|   mOutlineProvider = android.view.ViewOutlineProvider$1 [id=0x6fcd7240]
|   mOverScrollMode = 1
|   mOverlay = null
|   mPaddingBottom = 0
|   mPaddingLeft = 0
|   mPaddingRight = 0
|   mPaddingTop = 0
|   mParent = android.view.ViewRootImpl [id=0x13313400]
|   mPendingCheckForLongPress = null
|   mPendingCheckForTap = null
|   mPerformClick = null
|   mPrivateFlags = 25201976
|   mPrivateFlags2 = 1611867680
|   mPrivateFlags3 = 4
|   mRecreateDisplayList = false
|   mRenderNode = android.view.RenderNode [id=0x12ffd880]
|   mResources = android.content.res.Resources [id=0x12c078e0]
|   mRight = 1080
|   mRightPaddingDefined = true
|   mScrollCache = null
|   mScrollX = 0
|   mScrollY = 0
|   mSendViewScrolledAccessibilityEvent = null
|   mSendViewStateChangedAccessibilityEvent = null
|   mSendingHoverAccessibilityEvents = false
|   mStateListAnimator = null
|   mSystemUiVisibility = 0
|   mTag = null
|   mTempNestedScrollConsumed = null
|   mTop = 0
|   mTouchDelegate = null
|   mTouchSlop = 24
|   mTransformationInfo = android.view.View$TransformationInfo [id=0x1349e7c0]
|   mTransientStateCount = 0
|   mTransitionName = null
|   mUnscaledDrawingCache = null
|   mUnsetPressedState = null
|   mUserPaddingBottom = 0
|   mUserPaddingEnd = -2147483648
|   mUserPaddingLeft = 0
|   mUserPaddingLeftInitial = 0
|   mUserPaddingRight = 0
|   mUserPaddingRightInitial = 0
|   mUserPaddingStart = -2147483648
|   mVerticalScrollFactor = 0.0
|   mVerticalScrollbarPosition = 0
|   mViewFlags = 402655360
|   mWindowAttachCount = 1
* Instance of android.view.View$AttachInfo
|   mAccessibilityFetchFlags = 0
|   mAccessibilityFocusDrawable = null
|   mAccessibilityWindowId = 2147483647
|   mApplicationScale = 1.0
|   mCanvas = null
|   mContentInsets = android.graphics.Rect [id=0x13364ee0]
|   mDebugLayout = false
|   mDisabledSystemUiVisibility = 0
|   mDisplay = android.view.Display [id=0x12f75b50]
|   mDisplayState = 2
|   mDrawingTime = 137551407
|   mForceReportNewAttributes = false
|   mGivenInternalInsets = android.view.ViewTreeObserver$InternalInsetsInfo [id=0x13364f40]
|   mGlobalSystemUiVisibility = 0
|   mHandler = android.view.ViewRootImpl$ViewRootHandler [id=0x13364d00]
|   mHardwareAccelerated = true
|   mHardwareAccelerationRequested = true
|   mHardwareRenderer = android.view.ThreadedRenderer [id=0x13323dc0]
|   mHasNonEmptyGivenInternalInsets = false
|   mHasSystemUiListeners = true
|   mHasWindowFocus = true
|   mHighContrastText = false
|   mIWindowId = null
|   mIgnoreDirtyState = false
|   mInTouchMode = true
|   mInvalidateChildLocation = int[] [id=0x13370060;length=2;size=24]
|   mKeepScreenOn = false
|   mKeyDispatchState = android.view.KeyEvent$DispatcherState [id=0x13364fc0]
|   mOverscanInsets = android.graphics.Rect [id=0x13364ec0]
|   mOverscanRequested = false
|   mPanelParentWindowToken = null
|   mPendingAnimatingRenderNodes = null
|   mPoint = android.graphics.Point [id=0x133582f0]
|   mRecomputeGlobalAttributes = false
|   mRootCallbacks = android.view.ViewRootImpl [id=0x13313400]
|   mRootView = com.android.internal.policy.impl.PhoneWindow$DecorView [id=0x12eac000]
|   mScalingRequired = false
|   mScrollContainers = java.util.ArrayList [id=0x13364fa0]
|   mSession = android.view.IWindowSession$Stub$Proxy [id=0x13358290]
|   mSetIgnoreDirtyState = true
|   mStableInsets = android.graphics.Rect [id=0x13364f20]
|   mSystemUiVisibility = 0
|   mTempArrayList = java.util.ArrayList [id=0x133701a0]
|   mTmpInvalRect = android.graphics.Rect [id=0x133700c0]
|   mTmpLocation = int[] [id=0x13370080;length=2;size=24]
|   mTmpMatrix = android.graphics.Matrix [id=0x133582d0]
|   mTmpOutline = android.graphics.Outline [id=0x13370180]
|   mTmpRectList = java.util.ArrayList [id=0x13370120]
|   mTmpTransformLocation = float[] [id=0x133700a0;length=2;size=24]
|   mTmpTransformRect = android.graphics.RectF [id=0x133700e0]
|   mTmpTransformRect1 = android.graphics.RectF [id=0x13370100]
|   mTmpTransformation = android.view.animation.Transformation [id=0x13370140]
|   mTransparentLocation = int[] [id=0x13370040;length=2;size=24]
|   mTreeObserver = android.view.ViewTreeObserver [id=0x133656c0]
|   mTurnOffWindowResizeAnim = false
|   mUnbufferedDispatchRequested = false
|   mUse32BitDrawingCache = true
|   mViewRequestingLayout = null
|   mViewRootImpl = android.view.ViewRootImpl [id=0x13313400]
|   mViewScrollChanged = false
|   mViewVisibilityChanged = false
|   mVisibleInsets = android.graphics.Rect [id=0x13364f00]
|   mWindow = android.view.ViewRootImpl$W [id=0x13364e80]
|   mWindowId = null
|   mWindowLeft = 0
|   mWindowToken = android.view.ViewRootImpl$W [id=0x13364e80]
|   mWindowTop = 0
|   mWindowVisibility = 0
* Instance of android.view.ViewTreeObserver
|   mAlive = true
|   mOnComputeInternalInsetsListeners = null
|   mOnDrawListeners = null
|   mOnEnterAnimationCompleteListeners = null
|   mOnGlobalFocusListeners = null
|   mOnGlobalLayoutListeners = android.view.ViewTreeObserver$CopyOnWriteArray [id=0x1315a300]
|   mOnPreDrawListeners = android.view.ViewTreeObserver$CopyOnWriteArray [id=0x13345760]
|   mOnScrollChangedListeners = android.view.ViewTreeObserver$CopyOnWriteArray [id=0x12fd3220]
|   mOnTouchModeChangeListeners = java.util.concurrent.CopyOnWriteArrayList [id=0x133a1420]
|   mOnWindowAttachListeners = null
|   mOnWindowFocusListeners = null
|   mOnWindowShownListeners = null
|   mWindowShown = false
* Instance of android.view.ViewTreeObserver$CopyOnWriteArray
|   mAccess = android.view.ViewTreeObserver$CopyOnWriteArray$Access [id=0x12fa1960]
|   mData = java.util.ArrayList [id=0x12fd3240]
|   mDataCopy = null
|   mStart = false
* Instance of java.util.ArrayList
|   static $staticOverhead = byte[] [id=0x6fcffb29;length=16;size=32]
|   static MIN_CAPACITY_INCREMENT = 12
|   static serialVersionUID = 8683452581122892189
|   array = java.lang.Object[] [id=0x13094a40;length=12]
|   size = 1
|   modCount = 1
* Array of java.lang.Object[]
|   [0] = com.couchsurfing.mobile.ui.events.detail.EventDetailsView$1 [id=0x12fa1950]
|   [1] = null
|   [2] = null
|   [3] = null
|   [4] = null
|   [5] = null
|   [6] = null
|   [7] = null
|   [8] = null
|   [9] = null
|   [10] = null
|   [ 

Source: (StackOverflow)

Stuck at "Dumping memory, app will freeze. Brrr." message

I'm trying to use LeakCanary to detect memory leaks in my app, but it does not go further than the message "Dumping memory, app will freeze. Brrr." I've been waiting for about 20 minutes or so, but no changes. Same behaviour on these devices: 1. Asus fonepad 8 (Android 5.0 stock) 2. Sony Xperia SP (Android 5.1.1 CM 12.1 custom) 3. HTC Desire C (Android 4.4 CM 11 custom)

I did everything as its advised in instruction:

public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    LeakCanary.install(this);
  }
}

Source: (StackOverflow)

Avoiding memory leak from crittercism in android

We use crittercism in our app for crash reporting. We've recently began using LeakCanary, and the app is finding leaks which appear to be caused by crittercism. Does anyone know of a way to configure or manipulate crittercism's android SDK to avoid this leak?

* com.my.app.activity.MyActivity has leaked:
* GC ROOT com.my.app.AppInstance.mActivityLifecycleCallbacks
* references java.util.ArrayList.array
* references array java.lang.Object[].[1]
* references crittercism.android.av.g
* references crittercism.android.bd.mPendingResult
* references android.app.LoadedApk$ReceiverDispatcher$Args.this$0
* references android.app.LoadedApk$ReceiverDispatcher.mContext
* leaks com.my.app.activity.MyActivity instance

* Device: motorola motorola XT1254 quark_verizon
* Android Version: 4.4.4 API: 19 LeakCanary: 1.3.1
* Durations: watch=6008ms, gc=210ms, heap dump=3730ms, analysis=29858ms

Source: (StackOverflow)

Memory leak by AttachInfo.mRootCallbacks reported by LeakCanary

I'm using LeakCanary library to troubleshoot a memory leak of my activity. After fixing several issues I got this logcat output :

  • com.MyPackage.activities.MyActivity has leaked:
  • GC ROOT com.MyPackage.MyView.mAttachInfo
  • references android.view.View$AttachInfo.mRootCallbacks
  • references android.view.ViewRootImpl.mContext
  • leaks com.MyPackage.activities.MyActivity instance
  1. I have no idea what this reference mean. The view is keeping a reference to the activity which prevents it from being GCed? When and how should I handle it?
  2. I used Eclipse memory analyze tool tool and found that there are actually no instances of my activity alive. Does that make sense?

Also opened this as an issue for canary.


Edit 1 : relevant implementation :

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

     MyView.InteractionCallbacks interactionCallback = new InteractionCallbackImplementation(
     mNewView = new MyView(getActivity().getApplicationContext(), 
     LayoutInflater li = (LayoutInflater) getActivity().getApplicationContext().getSystemService(
                                                                                          Service.LAYOUT_INFLATER_SERVICE);
     ViewGroup fragmentLayout = (ViewGroup) li.inflate(R.layout.fragment_layout, container, false);
     fragmentLayout.addView(mNewView, 0);
}

public static class InteractionCallbackImplementation implements MyView.InteractionCallbacks {

        WeakReference<MyFragment> frag;
        public InteractionCallbackImplementation(MyFragment myFragment){
            frag = new WeakReference<myFragment>(myFragment);
        }

        @Override
        public void partsSelected(long[] parts) {
               // ...
        }
}

The view : Is a part of external jar which handles gl rendering. has a reference to the fragment.

public class MyView extends GLSurfaceView implements Renderer {
     private void runOnUiThread(Runnable runnable) {
          this.getHandler().post(runnable);
     }
}

What I know is that when I leave the activity :

  1. The activity is destroyed and there are no instances of the activity anymore.
  2. The fragment is destroyed.
  3. The view is detached.

So why would the canary library claim that - there’s a leaked reference?

When and how should a view lose it's reference to it's context?


Source: (StackOverflow)

Reading LeakCanary Log

I have installed LeakCanary to see if my app had memory leaks.

It appears so, but I can't read the log, any one can tell me how, or give the good tutorial I can't find???

In the doc in github, it says:

Once you have the leak trace, figure out which reference in the path should not exist. Then figure out why that reference still exists.

But I don't know how to do it.

Tx!

Here is my log.

In com.myapp.mobile:1.3:33.
* LEAK CAN BE IGNORED.
* com.myapp.mobile.SplashScreen has leaked:
* GC ROOT static android.view.ViewConfiguration.
* references android.util.SparseArray.mValues
* references array java.lang.Object[].[0]
* references android.view.ViewConfiguration.mContext
* leaks com.myapp.mobile.SplashScreen instance
[ 07-17 14:59:07.213 32231:  770 D/LeakCanary ]

* Device: samsung samsung SGH-I337M jflteub
* Android Version: 4.4.2 API: 19 LeakCanary: 1.3.1
* Durations: watch=5014ms, gc=155ms, heap dump=1322ms, 
[ 07-17 14:59:07.213 32231:  770 D/LeakCanary ]

* Class android.view.ViewConfiguration
|   static $staticOverhead = byte[] [
|   static DEFAULT_LONG_PRESS_TIMEOUT = 500
|   static DOUBLE_TAP_MIN_TIME = 40
|   static DOUBLE_TAP_SLOP = 100
|   static DOUBLE_TAP_TIMEOUT = 300
|   static DOUBLE_TAP_TOUCH_SLOP = 8
|   static EDGE_SLOP = 12
|   static FADING_EDGE_LENGTH = 12
|   static GLOBAL_ACTIONS_KEY_TIMEOUT = 500
|   static HOVER_TAP_SLOP = 20
|   static HOVER_TAP_TIMEOUT = 150
|   static JUMP_TAP_TIMEOUT = 500
|   static KEY_REPEAT_DELAY = 50
|   static MAXIMUM_DRAWING_CACHE_SIZE = 1536000
|   static MAXIMUM_FLING_VELOCITY = 8000
|   static MINIMUM_FLING_VELOCITY = 50
|   static OVERFLING_DISTANCE = 6
|   static OVERSCROLL_DISTANCE = 0
|   static PAGING_TOUCH_SLOP = 16
|   static PRESSED_STATE_DURATION = 64
|   static SCROLL_BAR_DEFAULT_DELAY = 300
|   static SCROLL_BAR_FADE_DURATION = 250
|   static SCROLL_BAR_SIZE = 10
|   static SCROLL_FRICTION = 0.015
|   static 
|   static TAP_TIMEOUT = 180
|   static TOUCH_SLOP = 8
|   static WINDOW_TOUCH_SLOP = 16
|   static ZOOM_CONTROLS_TIMEOUT = 3000
|   static sConfigurations = android.util.SparseArray [
* Instance of android.util.SparseArray
|   static $staticOverhead = byte[] [
|   static DELETED = java.lang.Object [id=0x41884b48]
|   mValues = java.lang.Object[] [id=0x421af900;length=5
|   mKeys = int[] [id=0x421af8d8;length=5;size=32]
|   mSize = 1
|   mGarbage = false
* Array of java.lang.Object[]
|   [0] = android.view.ViewConfiguration [id=0x42a8a2d8]
|   [1] = null
|   [2] = null
|   [3] = null
|   [4] = null
* Instance of android.view.ViewConfiguration
|   static $staticOverhead = byte[] [
|   static DEFAULT_LONG_PRESS_TIMEOUT = 500
|   static DOUBLE_TAP_MIN_TIME = 40
|   static DOUBLE_TAP_SLOP = 100
|   static DOUBLE_TAP_TIMEOUT = 300
|   static DOUBLE_TAP_TOUCH_SLOP = 8
|   static EDGE_SLOP = 12
|   static FADING_EDGE_LENGTH = 12
|   static GLOBAL_ACTIONS_KEY_TIMEOUT = 500
|   static HOVER_TAP_SLOP = 20
|   static HOVER_TAP_TIMEOUT = 150
|   static JUMP_TAP_TIMEOUT = 500
|   static KEY_REPEAT_DELAY = 50
|   static MAXIMUM_DRAWING_CACHE_SIZE = 1536000
|   static MAXIMUM_FLING_VELOCITY = 8000
|   static MINIMUM_FLING_VELOCITY = 50
|   static OVERFLING_DISTANCE = 6
|   static OVERSCROLL_DISTANCE = 0
|   static PAGING_TOUCH_SLOP = 16
|   static PRESSED_STATE_DURATION = 64
|   static SCROLL_BAR_DEFAULT_DELAY = 300
|   static SCROLL_BAR_FADE_DURATION = 250
|   static SCROLL_BAR_SIZE = 10
|   static SCROLL_FRICTION = 0.015
|   static 
|   static TAP_TIMEOUT = 180
|   static TOUCH_SLOP = 8
|   static WINDOW_TOUCH_SLOP = 16
|   static ZOOM_CONTROLS_TIMEOUT = 3000
|   static sConfigurations = android.util.SparseArray [
|   mContext = com.myapp.mobile.SplashScreen [
|   mDoubleTapSlop = 300
|   mDoubleTapTouchSlop = 48
|   mEdgeSlop = 36
|   mFadingEdgeLength = 36
|   mFadingMarqueeEnabled = false
|   mMaximumDrawingCacheSize = 8294400
|   mMaximumFlingVelocity = 24000
|   mMinimumFlingVelocity = 150
|   mOverflingDistance = 18
|   mOverscrollDistance = 0
|   mPagingTouchSlop = 96
|   mScrollbarSize = 30
|   mTouchSlop = 48
|   mWindowTouchSlop = 48
|   sHasPermanentMenuKey = true
|   sHasPermanentMenuKeySet = true
* Instance of com.myapp.mobile.SplashScreen
|   ctx = com.myapp.mobile.SplashScreen [id=0x42a7c450]
|   prefs = android.app.SharedPreferencesImpl [
|   mActionBar = null
|   mActivityInfo = android.content.pm.ActivityInfo [
|   mAllLoaderManagers = android.util.ArrayMap [
|   mApplication = com.myapp.mobile.MyApplication [
|   mWindowManager = android.view.WindowManagerImpl [
|   mWindow = com.android.internal.policy.impl.
|   mUiThread = java.lang.Thread [id=0x4180aea0]
|   mTranslucentCallback = null
|   mComponent = android.content.ComponentName [
|   mToken = android.os.BinderProxy [id=0x42a03820]
|   mContainer = android.app.Activity$1 [id=0x42a7c5c8]
|   mCurrentConfig = android.content.res.Configuration [
|   mDecor = null
|   mTitle = java.lang.String [id=0x42a85570]
|   mDefaultKeySsb = null
|   mSearchManager = null
|   mResultData = null
|   mEmbeddedID = null
|   mParent = null
|   mMenuInflater = null
|   mFragments = android.app.FragmentManagerImpl [
|   mHandler = android.os.Handler [id=0x42a7c670]
|   mManagedDialogs = null
|   mInstanceTracker = android.os.
|   mInstrumentation = android.app.Instrumentation [
|   mIntent = android.content.Intent [id=0x42a03568]
|   mLastNonConfigurationInstances = null
|   mLoaderManager = null
|   mManagedCursors = java.util.ArrayList [id=0x42a7c5d8
|   mMainThread = android.app.ActivityThread [
|   mLoadersStarted = false
|   mIdent = 1123061480
|   mFinished = true
|   mEnableDefaultActionBarUp = false
|   mResultCode = 0
|   mDoReportFullyDrawn = false
|   mResumed = false
|   mDestroyed = true
|   mStartedActivity = false
|   mStopped = true
|   mTemporaryPause = false
|   mDefaultKeyMode = 0
|   mTitleColor = 0
|   mTitleReady = true
|   mConfigChangeFlags = 0
|   mCheckedForLoaderManager = true
|   mChangingConfigurations = false
|   mVisibleFromClient = true
|   mVisibleFromServer = false
|   mChangeCanvasToTranslucent = false
|   mWindowAdded = true
|   mCalled = true
|   mBase = android.app.ContextImpl [id=0x42a7c690]
|   mInflater = com.android.internal.policy.impl.
|   mOverrideConfiguration = null
|   mResources = android.content.res.Resources [
|   mTheme = android.content.res.Resources$Theme [
|   mThemeResource = 2131296377
|   mBase = android.app.ContextImpl [id=0x42a7c690]

In com.myapp.mobile:1.3:33.
* com.myapp.mobile.MetricaTabs has leaked:
* GC ROOT static com.myapp.mobile.MetricaTabs.ctx
* leaks com.myapp.mobile.MetricaTabs instance
[ 07-17 15:00:10.945 32231: 1926 D/LeakCanary ]

* Device: samsung samsung SGH-I337M jflteub
* Android Version: 4.4.2 API: 19 LeakCanary: 1.3.1
* Durations: watch=5015ms, gc=218ms, heap dump=1071ms, 
[ 07-17 15:00:10.945 32231: 1926 D/LeakCanary ]

* Class com.myapp.mobile.MetricaTabs
|   static $staticOverhead = byte[] [
|   static ENCUESTA = 5
|   static METRICA_DATOS = 0
|   static METRICA_ENCUESTAS = 1
|   static TEN_SECONDS = 10000
|   static ctx = com.myapp.mobile.MetricaTabs [
|   static errorList = java.util.ArrayList [
|   static idCaptura = 4
|   static idEncuesta = 0
|   static imageFileUri = null
|   static lMetricas = java.util.ArrayList [
|   static listLV = null
|   static rclForm = android.support.v7.widget.
|   static transparentEt = android.support.v7.widget.
* Instance of com.myapp.mobile.MetricaTabs
|   static $staticOverhead = byte[] [
|   static ENCUESTA = 5
|   static METRICA_DATOS = 0
|   static METRICA_ENCUESTAS = 1
|   static TEN_SECONDS = 10000
|   static ctx = com.myapp.mobile.MetricaTabs [
|   static errorList = java.util.ArrayList [
|   static idCaptura = 4
|   static idEncuesta = 0
|   static imageFileUri = null
|   static lMetricas = java.util.ArrayList [
|   static listLV = null
|   static rclForm = android.support.v7.widget.
|   static transparentEt = android.support.v7.widget.
|   ab = android.support.v7.internal.app.
|   adbForm = null
|   eh = com.myapp.mobile.sqlite.EncuestaHandler [
|   tabLayout = android.support.design.widget.TabLayout 
|   loc = null
|   mCaptura = null
|   mEncuesta = null
|   mSectionsPagerAdapter = com.myapp.mobile.
|   mViewPager = android.support.v4.view.ViewPager [
|   metrica = null
|   prefs = android.app.SharedPreferencesImpl [
|   numTab = 0
|   saveAndNew = false
|   encuesta = 0
|   mDelegate = android.support.v7.app.
|   mAllLoaderManagers = android.support.v4.util.
|   mLoaderManager = null
|   mContainer = android.support.v4.app.
|   mHandler = android.support.v4.app.
|   mFragments = android.support.v4.app.
|   mCreated = true
|   mCheckedForLoaderManager = true
|   mLoadersStarted = false
|   mOptionsMenuInvalidated = false
|   mReallyStopped = true
|   mResumed = false
|   mRetaining = false
|   mStopped = true
|   mActionBar = null
|   mActivityInfo = android.content.pm.ActivityInfo [
|   mAllLoaderManagers = android.util.ArrayMap [
|   mApplication = com.myapp.mobile.MyApplication [
|   mWindowManager = android.view.WindowManagerImpl [
|   mWindow = com.android.internal.policy.impl.
|   mUiThread = java.lang.Thread [id=0x4180aea0]
|   mTranslucentCallback = null
|   mComponent = android.content.ComponentName [
|   mToken = android.os.BinderProxy [id=0x42f18c40]
|   mContainer = android.app.Activity$1 [id=0x42a92978]
|   mCurrentConfig = android.content.res.Configuration [
|   mDecor = null
|   mTitle = java.lang.String [id=0x42fb8850]
|   mDefaultKeySsb = null
|   mSearchManager = null
|   mResultData = null
|   mEmbeddedID = null
|   mParent = null
|   mMenuInflater = null
|   mFragments = android.app.FragmentManagerImpl [
|   mHandler = android.os.Handler [id=0x429fd658]
|   mManagedDialogs = null
|   mInstanceTracker = android.os.
|   mInstrumentation = android.app.Instrumentation [
|   mIntent = android.content.Intent [id=0x42f2ded8]
|   mLastNonConfigurationInstances = null
|   mLoaderManager = null
|   mManagedCursors = java.util.ArrayList [id=0x42a145a8
|   mMainThread = android.app.ActivityThread [
|   mLoadersStarted = false
|   mIdent = 1136727720
|   mFinished = true
|   mEnableDefaultActionBarUp = false
|   mResultCode = 0
|   mDoReportFullyDrawn = false
|   mResumed = false
|   mDestroyed = true
|   mStartedActivity = false
|   mStopped = true
|   mTemporaryPause = false
|   mDefaultKeyMode = 0
|   mTitleColor = 0
|   mTitleReady = true
|   mConfigChangeFlags = 0
|   mCheckedForLoaderManager = true
|   mChangingConfigurations = false
|   mVisibleFromClient = true
|   mVisibleFromServer = true
|   mChangeCanvasToTranslucent = false
|   mWindowAdded = true
|   mCalled = true
|   mBase = android.app.ContextImpl [id=0x429f95b0]
|   mInflater = com.android.internal.policy.impl.
|   mOverrideConfiguration = null
|   mResources = android.content.res.Resources [
|   mTheme = android.content.res.Resources$Theme [
|   mThemeResource = 2131296377
|   mBase = android.app.ContextImpl [id=0x429f95b0]

Source: (StackOverflow)

Android Leak Canary Log

I am using Leaky Canary to detect memory leaks in my app. While I was able to get rid of 2-3 issues before this, I cannot figure out where the leak is from this log

11-14 18:05:05.330 32099-3554/? D/LeakCanary: In com.prism.prism:1.1:2.
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * com.prism.prism.RatePicActivity_ has leaked:
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * GC ROOT android.database.ContentObserver$Transport.mContentObserver
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * references android.app.Activity$SettingsObserver.this$0
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * leaks com.prism.prism.RatePicActivity_ instance
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Reference Key: 29bcc62a-b7e2-4d80-8cda-be2f841f19aa
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Device: samsung samsung GT-I9300 m0xx
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Android Version: 4.4.4 API: 19 LeakCanary: 1.3.1
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Durations: watch=5024ms, gc=176ms, heap dump=1129ms, analysis=12787ms
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Details:
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Instance of android.database.ContentObserver$Transport
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mContentObserver = android.app.Activity$SettingsObserver [id=0x41b22d00]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mDescriptor = java.lang.String [id=0x41913c70]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mOwner = android.database.ContentObserver$Transport [id=0x41b1a878]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mObject = 1570915608
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Instance of android.app.Activity$SettingsObserver
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   this$0 = com.prism.prism.RatePicActivity_ [id=0x41ba5aa0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mHandler = android.os.Handler [id=0x41c45f78]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mLock = java.lang.Object [id=0x41c7c220]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mTransport = android.database.ContentObserver$Transport [id=0x41b1a878]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: * Instance of com.prism.prism.RatePicActivity_
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   onViewChangedNotifier_ = org.androidannotations.api.view.OnViewChangedNotifier [id=0x41cceb68]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   application = com.prism.prism.MyApplication_ [id=0x41b26fe0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   backgroundImageView = android.support.v7.widget.AppCompatImageView [id=0x41ba1960]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   fragment_container = android.widget.FrameLayout [id=0x41b6f098]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mDelegate = android.support.v7.app.AppCompatDelegateImplV14 [id=0x4226a548]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mMediaController = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mFragments = android.support.v4.app.FragmentController [id=0x41cd05c0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mHandler =     android.support.v4.app.FragmentActivity$1 [id=0x41c63520]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mCreated = true
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mOptionsMenuInvalidated = false
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mReallyStopped = true
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mRequestedPermissionsFromFragment = false
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mResumed = false
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mRetaining = false
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mStopped = true
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mActionBar = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mActivityInfo = android.content.pm.ActivityInfo [id=0x41c6ab08]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mAllLoaderManagers = android.util.ArrayMap [id=0x41cab818]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mApplication = com.prism.prism.MyApplication_ [id=0x41b26fe0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mWindowManager = android.view.WindowManagerImpl [id=0x41c48e60]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mWindow = com.android.internal.policy.impl.PhoneWindow [id=0x41b966a0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mUiThread = java.lang.Thread [id=0x417e1d80]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mTranslucentCallback = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mComponent = android.content.ComponentName [id=0x41c76c08]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mToken = android.os.BinderProxy [id=0x41c730f8]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mContainer = android.app.Activity$1 [id=0x41cffe98]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mCurrentConfig = android.content.res.Configuration [id=0x41df0360]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mDecor = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mTitle = java.lang.String [id=0x41b66db8]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mDefaultKeySsb = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mSettingsObserver = android.app.Activity$SettingsObserver [id=0x41b22d00]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mSearchManager = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mEmbeddedID = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mResultData = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mParent = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mFragments = android.app.FragmentManagerImpl [id=0x41ed3590]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mHandler = android.os.Handler [id=0x41c45f78]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mMenuInflater = null
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mImmerseModeRunnable = android.app.Activity$3 [id=0x41cebb80]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mInstanceTracker = android.os.StrictMode$InstanceTracker [id=0x41cf0dc0]
11-14 18:05:05.330 32099-3554/? D/LeakCanary: |   mInstrumentation = android.app.Instrumentation [id=0x41b26818]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mIntent = android.content.Intent [id=0x41b19e40]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mLastNonConfigurationInstances = null
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mLoaderManager = null
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mManagedDialogs = null
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mMainThread = android.app.ActivityThread [id=0x41b16958]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mManagedCursors = java.util.ArrayList [id=0x41c6d948]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mLoadersStarted = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mIdent = 1103360840
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mFinished = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mResultCode = 0
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mEnableDefaultActionBarUp = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mResumed = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mDoReportFullyDrawn = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mDestroyed = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mStartedActivity = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mStopped = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mTemporaryPause = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mDefaultKeyMode = 0
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mTitleColor = 0
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mTitleReady = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mConfigChangeFlags = 0
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mCheckedForLoaderManager = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mChangingConfigurations = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mVisibleFromClient = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mVisibleFromServer = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mChangeCanvasToTranslucent = false
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mWindowAdded = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mCalled = true
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mBase = uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper [id=0x41c522b8]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mInflater = uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater [id=0x41df9618]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mOverrideConfiguration = null
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mResources = android.content.res.XResources [id=0x41b22d80]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mTheme = android.content.res.Resources$Theme [id=0x41c48c10]
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mThemeResource = 2131492994
11-14 18:05:05.335 32099-3554/? D/LeakCanary: |   mBase = uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper [id=0x41c522b8]
11-14 18:05:05.335 32099-3554/? E/LeakCanary: Leak result dropped because we already store 7 leak traces.

I am unable to tell where the memory leak is occurring in this case. Can someone point out how to go about identifying it?


Source: (StackOverflow)

Cant build Gradle for LeakCanary library

I tried to build Gradle:

Executing command: "--stacktrace"

FAILURE: Build failed with an exception.

  • Where: Build file 'H:\Nin_in_the_winD\working.space\development\branch\eazy\build.gradle' line: 2

  • What went wrong: A problem occurred evaluating root project 'eazy'.

    Could not find method debugCompile() for arguments [com.squareup.leakcanary:leakcanary-android:1.3.1@aar] on root project 'eazy'.

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'eazy'. at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:76) at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$1.run(DefaultScriptPluginFactory.java:148) at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156) at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39) at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26) at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34) at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55) at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:487) at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:85) at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42) at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35) at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129) at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106) at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86) at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90) at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28) at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28) at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:50) at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:27) at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40) at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169) at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237) at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210) at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35) at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24) at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206) at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169) at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) at org.gradle.launcher.Main.doAction(Main.java:33) at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54) at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35) at org.gradle.launcher.GradleMain.main(GradleMain.java:23) Caused by: org.gradle.api.internal.MissingMethodException: Could not find method debugCompile() for arguments [com.squareup.leakcanary:leakcanary-android:1.3.1@aar] on root project 'eazy'. at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68) at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56) at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:175) at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79) at build_4cypqr1onvufm2h2phqvhowz7$_run_closure1.doCall(H:\Nin_in_the_winD\working.space\development\branch\eazy\build.gradle:2) at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67) at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130) at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91) at org.gradle.api.internal.project.AbstractProject.dependencies(AbstractProject.java:838) at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:232) at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:127) at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:150) at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79) at build_4cypqr1onvufm2h2phqvhowz7.run(H:\Nin_in_the_winD\working.space\development\branch\eazy\build.gradle:1) at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:74) ... 35 more

Here is my gradle.build:

dependencies {
  debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1@aar'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1@aar'
}
repositories {
  mavenCentral()
}

Source: (StackOverflow)

aapt finished with non-zero exit value 1

Recently I'm trying to use LeakCanary to fix OOM(out of memory) issues for my Android app. And I added

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'

to my build.gradle, following the instructions on LeakCanary website. After gradle build, I got

"/android-sdk/android-sdk_r22.6.2-linux/build-tools/21.1.1/aapt'' finished with non-zero exit value 1 

This is part of my build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}

apply plugin: 'android'
apply plugin: 'maven'

android {
    compileSdkVersion 19
    buildToolsVersion '22.0.1'

    defaultConfig {
        multiDexEnabled true
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            res.srcDirs = ['res']
        }

        instrumentTest.setRoot('tests')
    }

    dexOptions {
        jumboMode = true
        preDexLibraries = false
        javaMaxHeapSize = '2g'
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    maven {
        url "http://XXXXX/nexus/content/repositories/releases"
    }
}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile(name: 'ShortcutBadger-1.0.1', ext: 'aar')
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
}

Source: (StackOverflow)

Memory Leak on AppCompatActivity using LeakCanary

I use LeakCanary and unfortunately got a leak and here is the logcat:

05-10 18:13:00.377    9098-9965/com.ponnex.justdrive D/LeakCanary﹕ In com.ponnex.justdrive:1.0:1.
* com.ponnex.justdrive.DebuggingActivity has leaked:
* GC ROOT static android.support.v4.content.LocalBroadcastManager.mInstance
* references android.support.v4.content.LocalBroadcastManager.mReceivers
* references java.util.HashMap.table
* references array java.util.HashMap$HashMapEntry[].[51]
* references java.util.HashMap$HashMapEntry.key
* references com.ponnex.justdrive.DebuggingActivity$3.this$0 (anonymous class extends android.content.BroadcastReceiver)
* leaks com.ponnex.justdrive.DebuggingActivity instance
* Reference Key: 4fea07d9-9369-4618-a8e0-9e63b3e1b908
* Device: samsung samsung GT-I9100 pa_i9100
* Android Version: 5.1.1 API: 22
* Durations: watch=5219ms, gc=244ms, heap dump=4978ms, analysis=19968ms

This is my DebuggingActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
LeakCanary.install(getApplication());
setContentView(R.layout.activity_debugging);
activityTV = (TextView) findViewById(R.id.debugText);
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(screenReceiver, new IntentFilter("com.ponnex.justdrive.ActivityRecognitionIntentService"));

}
private BroadcastReceiver screenReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String activity = intent.getStringExtra("Activity");
        updateUI(activity);
    }
};

public static void updateUI(String activity) {
    activityTV.setText(activity);
}

I've been checking my activity and tracing it out but I don't know how to fix this any help? :D

If you need more from my activity code I'll be glad to add or post them here ;)

---EDIT---

I also got a leak from another activity refering to snackbar(Snackbar by Nispok)

05-10 18:27:43.161   9098-16222/com.ponnex.justdrive D/LeakCanary﹕ In com.ponnex.justdrive:1.0:1.
* com.ponnex.justdrive.MainActivity has leaked:
* GC ROOT static com.nispok.snackbar.SnackbarManager.currentSnackbar
* references com.nispok.snackbar.Snackbar.mContext
* leaks com.ponnex.justdrive.MainActivity instance
* Reference Key: 1982a1a8-e66e-4218-9b5a-8f907ee26a7f
* Device: samsung samsung GT-I9100 pa_i9100
* Android Version: 5.1.1 API: 22
* Durations: watch=5291ms, gc=315ms, heap dump=4443ms, analysis=21801ms

Source: (StackOverflow)

LeakCanary - Activity is leaked as it implements SyncStatusObserver

I am using LeakCanary to identify memory leaks. I have an Activity which adds itself as the StatusChangeObserver in onResume as below:

    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING |
            ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;

    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, this);

And stops listening onPause

    ContentResolver.removeStatusChangeListener(mSyncObserverHandle);

When I exit the Activity, LeakCanary reports my Activity is leaked. Below is gist of the leak trace:

     * com.sample.android.MyListActivity has leaked:
     * GC ROOT android.content.ContentResolver$1.val$callback(anonymous class extends android.content.ISyncStatusObserver$Stub)
     * leaks com.sample.android.MyListActivity instance
     [ 06-11 15:35:23.123 11823:13392 D/LeakCanary ]
     * Reference Key: 1eaf447d-055c-4767-bb3f-56b12c7a4dae
     * Device: motorola motorola XT1022 condor_retaildsds
     * Android Version: 4.4.4 API: 19 LeakCanary: 1.3.1
     * Durations: watch=5029ms, gc=147ms, heap dump=693ms, analysis=15159ms
     [ 06-11 15:35:23.123 11823:13392 D/LeakCanary ]

I have tested on API 19 and 22. I would like to know if its a problem with my code or leakcanary or sdk.

Thanks in advance!


Source: (StackOverflow)