android - 读取 LeakCanary 日志

标签 android memory-leaks leakcanary

我已经安装了 LeakCanary 以查看我的应用程序是否存在内存泄漏。

看起来是这样,但是我看不到日志,谁能告诉我怎么做,或者给出我找不到的好的教程???

github 中的文档中,它说:

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

但是我不知道怎么做。

谢谢!

这是我的日志。

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]

最佳答案

这个库真是太棒了,让我省去了很多头疼的事情。在许多情况下,它会准确显示泄漏位置。但在您的情况下,泄漏发生在您的 Activity 类本身,因此 LeakCanary 会告诉您来自哪个类。您可能将该 Activity 注册为另一个类的监听器,而忘记注销它。我的建议是您在 Activity 类中搜索对 this 的引用。其中每一个都可能是潜在的泄漏。

关于android - 读取 LeakCanary 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483933/

相关文章:

android - 如何更改 Xamarin for android 上的条目?

node.js - 使用下载管理器取消下载时 Nodejs 内存泄漏

android - 绑定(bind)服务泄漏内存

android - 我的 leakcanary 在工作吗?怎么知道?

android - 使应用程序类单例会导致内存泄漏吗?

android - 在两个 Activity 之间传递 bool Intent

java - 如何降低 onClick() 方法内的圈复杂度

ios - SKNode 子类中的 __stack_chk_fail

android - 如何使 320x480 ImageView 填满整个模拟器屏幕(尺寸为 320x480 mdpi)?

C - 使用双指针动态内存分配