我对这个场景比较陌生,没有什么编程背景,因此如果我问一些愚蠢的问题,我会提前道歉。
我正在使用SupportMapFragment显示一个google地图。我这样做是为了防止onDestroyView()中出现泄漏,但是不知道这是对还是错?
@Override
protected void onDestroy() {
super.onDestroy();
mMap.clear();
mapView.onDestroy();
}
完整代码如下:
â GC Root: Local variable in native code
â
ââ com.google.maps.api.android.lib6.gmm6.vector.n instance
â Leaking: UNKNOWN
â Retaining 1391172 bytes in 9076 objects
â Thread name: 'RenderDrive'
â â n.e
â ~
ââ com.google.maps.api.android.lib6.gmm6.vector.p instance
â Leaking: UNKNOWN
â Retaining 1391005 bytes in 9073 objects
â â p.k
â ~
ââ com.google.maps.api.android.lib6.gmm6.api.ac instance
â Leaking: UNKNOWN
â Retaining 1390953 bytes in 9072 objects
â View not part of a window view hierarchy
â View.mAttachInfo is null (view detached)
â View.mWindowAttachCount = 1
â mContext instance of android.app.Application
â â ac.mParent
â ~~~~~~~
ââ android.widget.FrameLayout instance
â Leaking: UNKNOWN
â Retaining 405651 bytes in 5497 objects
â View not part of a window view hierarchy
â View.mAttachInfo is null (view detached)
â View.mWindowAttachCount = 1
â mContext instance of android.app.Application
â â FrameLayout.mParent
â ~~~~~~~
ââ com.google.android.gms.maps.MapView instance
â Leaking: YES (View.mContext references a destroyed activity)
â Retaining 403455 bytes in 5482 objects
â View not part of a window view hierarchy
â View.mAttachInfo is null (view detached)
â View.mID = R.id.mapsView
â View.mWindowAttachCount = 1
â mContext instance of com.app.trikojis.MainActivity with mDestroyed = true
â â MapView.mContext
â°â com.app.trikojis.MainActivity instance
â Leaking: YES (ObjectWatcher was watching this because com.app.trikojis.MainActivity received Activity#onDestroy()
â callback and Activity#mDestroyed is true)
â Retaining 60455 bytes in 956 objects
â key = f3613896-cce8-4aac-a73a-d4a79700c719
â watchDurationMillis = 56451
â retainedDurationMillis = 51448
â mApplication instance of android.app.Application
â mBase instance of androidx.appcompat.view.ContextThemeWrapper, not wrapping known Android context
METADATA
Build.VERSION.SDK_INT: 28
Build.MANUFACTURER: samsung
LeakCanary version: 2.5
App process name: com.app.trikojis
Stats: LruCache[maxSize=3000,hits=5749,misses=110455,hitRate=4%]
RandomAccess[bytes=5714581,reads=110455,travel=48839777691,range=35924253,size=41590935]
Analysis duration: 11845 ms```