1

I am facing OOM issue as the supportMapFragment doesn't get destroyed.

Xml used:

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Code snippet :

mMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
GoogleMapOptions mapOptions = new GoogleMapOptions();
mapOptions.useViewLifecycleInFragment(true);
mMapFragment.newInstance(mapOptions);

//ondestroy calling

@Override
protected void onDestroy() {
    super.onDestroy();

    //clear all the data
    mMap.clear();
    mMapFragment.onDestroyView();

}

Followed the same as mentioned in the docs given: https://developers.google.com/android/reference/com/google/android/gms/maps/SupportMapFragment

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
witted_coder
  • 161
  • 1
  • 14

1 Answers1

1

As far as I see, you're not setting options here to your mMapFragment:

mMapFragment.newInstance(mapOptions);

You are creating one more SupportMapFragment with this option and it's lost, because you didn't assign it. Documentation says , that GoogleMapsOptions

Defines configuration GoogleMapOptions for a GoogleMap. These options can be used when adding a map to your application programmatically (as opposed to via XML).

If you want to call OnDestroy - you should create the map programmatically, without XML, like:

GoogleMapOptions mapOptions = new GoogleMapOptions();
mapOptions.useViewLifecycleInFragment(true);
mMapFragment = SupportMapFragment.newInstance(mapOptions);