gpt4 book ai didi

android - MapView保持上下文导致内存泄漏

转载 作者:行者123 更新时间:2023-11-29 15:40:41 33 4
gpt4 key购买 nike

我正在使用 MapView 版本。 10.0.1。我遇到了内存泄漏 MapView 持有 Activity 上下文。
LeakCanary 跟踪:

com.demo.app.ui.main.MainActivity has leaked:
GC ROOT wl.a
references oo.a
references maps.ad.L.g
references maps.ad.V.c
references maps.D.i.a
references maps.D.p.mParent
references android.widget.FrameLayout.mParent
references com.google.android.gms.maps.MapView.mContext
leaks com.demo.app.ui.main.MainActivity instance

最佳答案

泄漏很可能来自谷歌地图继续跟踪您的当前位置(如果您已设置)。所以将以下内容添加到您的 onDestroy()

@Override
public void onDestroy() {

if (mMapView != null) {
mMapView.onDestroy();
}

//Clean up resources from google map to prevent memory leaks.
//Stop tracking current location
if(mGoogleMap != null) {
mGoogleMap.setMyLocationEnabled(false);
}
super.onDestroy();
}

关于android - MapView保持上下文导致内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097269/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com