我已经安装了LeakCanary以查看我的应用是否有内存泄漏。
看起来如此,但我无法阅读日志,任何人都可以告诉我如何,或者提供我无法找到的好教程???
在github的文档中,它说:
获得泄漏迹线后,确定路径中的哪个参考不应存在。然后找出为什么该引用仍然存在。
但我不知道该怎么做。
的Tx!
这是我的日志。
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]
答案 0 :(得分:7)
这个图书馆真是太棒了,给我带来了很多麻烦。在许多情况下,它显示泄漏的确切位置。但在你的情况下,泄漏发生在你的活动类本身,所以LeakCanary会告诉你哪个类。您可能将该活动注册为另一个类的监听器,但忘记取消注册。我的建议是,在您的活动类中搜索对this
的引用。其中每一个都可能是潜在的泄漏。