[英]Memory leaks with MapView in a RecyclerView
I've already checked a bunch of other questions but none of the solutions have worked, I'm not using googleMap.setMyLocationEnabled(true) so thats not the problem. 我已经检查了很多其他问题,但是没有一个解决方案起作用,我没有使用googleMap.setMyLocationEnabled(true),所以那不是问题。
The adapter that I am loading the MapView in is located here . 我正在加载MapView的适配器位于此处 。
@Override
public void onMapReady(GoogleMap googleMap) {
//TODO: Allow user to update this 1-normal 2-satellite 3-Terrain
MapsInitializer.initialize(mContext);
gMap = googleMap;
gMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.setMapType(1);
googleMap.getUiSettings().setMapToolbarEnabled(false);
// If we have map data, update the map content.
if (mMapLocation != null) {
updateMapContents();
}
}
The map loads fine and functions, I'm just getting Out of Memory errors after orientation changes. 地图加载正常且功能正常,方向改变后我刚遇到“内存不足”错误。
Heres the output of LeakCanary: 这是LeakCanary的输出:
In me.calebjones.spacelaunchnow.debug:1.0.0-DEBUG:28. 在me.calebjones.spacelaunchnow.debug:1.0.0-DEBUG:28中。 * me.calebjones.spacelaunchnow.MainActivity has leaked: * GC ROOT maps.dz.af$af * references maps.dz.af.k * references maps.dg.p.mParent * references android.widget.FrameLayout.mParent * references com.google.android.gms.maps.MapView.mContext * leaks me.calebjones.spacelaunchnow.MainActivity instance * me.calebjones.spacelaunchnow.MainActivity已泄漏:* GC ROOT maps.dz.af $ af *参考maps.dz.af.k *参考maps.dg.p.mParent *参考android.widget.FrameLayout.mParent *参考com.google.android.gms.maps.MapView.mContext *泄漏me.calebjones.spacelaunchnow.MainActivity实例
There are GoogleMap in your ViewHolder. 您的ViewHolder中有GoogleMap。 You should override method onViewRecycled and clean memory: 您应该重写onViewRecycled方法并清理内存:
@Override
public void onViewRecycled(FriendViewHolder holder) {
if (holder.gMap != null) {
holder.gMap.clear();
holder.gMap.setMapType(GoogleMap.MAP_TYPE_NONE);
}
}
您是否尝试将其添加到清单中的活动标签中?
android:configChanges="orientation|screenSize"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.