我收到一个内存泄漏通知通过泄漏金丝雀它说我的片段实例泄漏由于eventlisteners和Arraylist.array举行的引用。不知道如何解决这个问题,有什么想法?如何避免数组列表事件侦听器发生内存泄漏?
@Override
ArrayList<myInterface> getnewList() {
ArrayList<myInterface> inst = new ArrayList<>();
inst.addAll(myRepository.getList());
inst.addAll(myRepository.getOtherList());
Collections.sort(inst, myRepository.myComparator);
return inst;
}
这里的泄漏跟踪这给泄漏的指示:
In com.myproject.project2.alpha.debug:3.0.0:3000000.
* com.project.newzy.dashboard.myListFragment has leaked:
* GC ROOT static com.myproject.repository.myRepository.eventListeners
* references java.util.ArrayList.array
* references array java.lang.Object[].[0]
* leaks com.project.newzy.dashboard.myListFragment instance
* Retaining: 251 KB.
* Reference Key: cc806908-52f6-42f5-be98-b39665dfa218
* Device: samsung samsung SM-J327P j3popltespr
* Android Version: 6.0.1 API: 23 LeakCanary: 1.5.1 1be44b3
* Durations: watch=5463ms, gc=131ms, heap dump=3776ms, analysis=40370ms
* Details:
* Class com.myproject.repository.myRepository
| static eventListeners = [email protected] (0x23085b80)
| static Comparator = [email protected] (0x230837d0)
| static $staticOverhead = byte[40]@584327169 (0x22d42001)
| static initialized = true
| static lock = [email protected] (0x230837e0)
| static cache = java.util.concurrent.C[email protected] (0x23081600)
* Instance of java.util.ArrayList
| static $staticOverhead = byte[16]@1893860329 (0x70e203e9)
| static MIN_CAPACITY_INCREMENT = 12
| static serialVersionUID = 8683452581122892189
| array = java.lang.Object[12]@591375616 (0x233fad00)
| size = 1
| modCount = 1
| shadow$_klass_ = java.util.ArrayList
| shadow$_monitor_ = 0
* Array of java.lang.Object[]
| [0] = [email protected] (0x2389c4e0)
| [1] = null
| [2] = null
| [3] = null
| [4] = null
| [5] = null
| [6] = null
| [7] = null
| [8] = null
| [9] = null
| [10] = null
| [11] = null
* Instance of com.project.newzy.dashboard.myListFragment
| static $staticOverhead = byte[16]@583464961 (0x22c6f801)
| static serialVersionUID = 0
| static $change = null
| adapter = [email protected] (0x233812e0)
| myRepository = [email protected] (0x2306ff10)
| inst = [email protected] (0x23400ce0)
| emptyLayout = [email protected] (0x2360bc00)
| emptyMessage = [email protected] (0x2360c400)
| floatingActionButton = [email protected] (0x2368d000)
| roomList = [email protected]120 (0x2360b800)
| selectedVGroupID = null
| listAdapter = [email protected] (0x233812e0)
| listDivider = [email protected] (0x232675f0)
| listManager = [email protected] (0x233abd60)
| listView = [email protected]120 (0x2360b800)
| mAdded = true
| mAnimationInfo = null
| mArguments = null
| mBackStackNesting = 0
| mCalled = true
| mCheckedForLoaderManager = true
| mChildFragmentManager = [email protected] (0x2318a900)
| mChildNonConfig = null
| mContainer = [email protected] (0x23a3a800)
| mContainerId = 2131755178
| mDeferStart = false
| mDetached = false
| mFragmentId = 2131755178
| mFragmentManager = [email protected] (0x23adc120)
| mFromLayout = false
| mHasMenu = false
| mHidden = false
| mHiddenChanged = false
| mHost = [email protected] (0x23ae1130)
| mInLayout = false
| mIndex = 1
| mInnerView = [email protected] (0x2360a400)
| mIsNewlyAdded = false
| mLoaderManager = null
| mLoadersStarted = true
| mMenuVisible = true
| mParentFragment = null
| mPostponedAlpha = 0.0
| mRemoving = false
| mRestored = false
| mRetainInstance = false
| mRetaining = false
| mSavedFragmentState = null
| mSavedViewState = null
| mState = 5
| mTag = [email protected] (0x232beb50)
| mTarget = null
| mTargetIndex = -1
| mTargetRequestCode = 0
| mUserVisibleHint = true
| mView = [email protected] (0x2360a400)
| mWho = [email protected] (0x233c2340)
| shadow$_klass_ = com.project.newzy.dashboard.myListFragment
| shadow$_monitor_ = -2032154546
* Excluded Refs:
| Field: android.view.inputmethod.InputMethodManager.mNextServedView
| Field: android.view.inputmethod.InputMethodManager.mServedView
| Field: android.view.inputmethod.InputMethodManager.mServedInputConnection
| Field: android.view.inputmethod.InputMethodManager.mCurRootView
| Field: android.os.UserManager.mContext
| Field: android.net.ConnectivityManager.sInstance
| Field: android.view.Choreographer$FrameDisplayEventReceiver.mMessageQueue (always)
| Thread:FinalizerWatchdogDaemon (always)
| Thread:main (always)
| Thread:LeakCanary-Heap-Dump (always)
| Class:java.lang.ref.WeakReference (always)
| Class:java.lang.ref.SoftReference (always)
| Class:java.lang.ref.PhantomReference (always)
| Class:java.lang.ref.Finalizer (always)
| Class:java.lang.ref.FinalizerReference (always)
请让我知道,如果你们以前遇到这一点,有关于如何去修复它的任何线索?
你能发表确切的消息吗? – Michael
刚刚添加了跟踪:) –
你如何使用金丝雀泄漏得到stace? @玛丽莎尼古拉斯只是好奇。 –