1

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.

The adapter that I am loading the MapView in is located here.

    @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:

In me.calebjones.spacelaunchnow.debug:1.0.0-DEBUG:28. * me.calebjones.spacelaunchnow.MainActivity has leaked: * GC ROOT maps.dz.af$a.f * 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

  • Retaining: 2.3 KB.
  • Reference Key: 9007ff6a-0072-49ce-b8cc-afc17cb19a76
  • Device: motorola google Nexus 6 shamu
  • Android Version: 6.0.1 API: 23 LeakCanary: 1.4-beta1 02804f3
  • Durations: watch=5791ms, gc=156ms, heap dump=11974ms, analysis=85902ms
Caleb Jones
  • 25
  • 3
  • 13

2 Answers2

2

There are GoogleMap in your ViewHolder. You should override method onViewRecycled and clean memory:

@Override
public void onViewRecycled(FriendViewHolder holder) {
if (holder.gMap != null) {
        holder.gMap.clear();
        holder.gMap.setMapType(GoogleMap.MAP_TYPE_NONE);
    }
}
Yazon2006
  • 3,684
  • 3
  • 25
  • 36
0

Did you try adding this to your manifest, in the activity tag?

 android:configChanges="orientation|screenSize"
Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53
  • Wow, really? That worked. Do you have some reading material for explaining what's going on with that? – Caleb Jones Mar 31 '16 at 18:17
  • 1
    Even having solved your problem, you shouldn't use this solution for every case. It is well explained here: http://stackoverflow.com/questions/7818717/why-not-use-always-androidconfigchanges-keyboardhiddenorientation – Sebastian Breit Mar 31 '16 at 18:34
  • Great, thats informative. Its definitely a bandaid though, I'm able to reproduce the memory leak when making other configuration changes unrelated...however those should be less frequent to a user. – Caleb Jones Mar 31 '16 at 19:57
  • I'm having the same issues, but your solution didn't work for me. – Luca D'Amico May 04 '16 at 11:17