android-maps-extensions icon indicating copy to clipboard operation
android-maps-extensions copied to clipboard

Memory leak class DelegatingOnCameraChangeListener i

Open maxime-kouemo opened this issue 8 years ago • 4 comments

First of all thank you for this library. I have been able to flawlessly add more than 5000 markers on the map. Yet, when I rotate the device, I have a memory leak. I changed the code to use only the googlemaps one without the elements of AME and I didn't have any memory leak while rotating the screen (yet I can't add that more markers with such fluidity). Here is the Java Heap Dump capture: tvjzlzv1pp5x_android_studio_trace

When I make a right click and jump to source it brings me here:

private class DelegatingOnCameraChangeListener implements com.google.android.gms.maps.GoogleMap.OnCameraChangeListener {

        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
            markerManager.onCameraChange(cameraPosition);
            if (onCameraChangeListener != null) {
                onCameraChangeListener.onCameraChange(cameraPosition);
            }
        }
    }

Keep in mind that in the destroy view of the mapview I use this (to make sure every thing is cleaned) :

if(googleMap != null) {
            googleMap.setOnMapClickListener(null);
            googleMap.setOnMarkerClickListener(null);
            googleMap.setInfoWindowAdapter(null);
            googleMap.setOnCameraChangeListener(null); // <--
            googleMap.setOnGroundOverlayClickListener(null);
            googleMap.setOnCameraMoveCanceledListener(null);
            googleMap.setOnCameraMoveListener(null);
            googleMap.setOnCameraMoveStartedListener(null);
            googleMap.setOnCircleClickListener(null);
            googleMap.setOnMyLocationChangeListener(null);
            googleMap.setOnMapLongClickListener(null);
            googleMap.setOnInfoWindowClickListener(null);
            googleMap.setOnInfoWindowCloseListener(null);
            googleMap.setOnInfoWindowLongClickListener(null);
            googleMap.setOnPoiClickListener(null);
            googleMap.setOnPolygonClickListener(null);
            googleMap.setOnPolylineClickListener(null);
            googleMap.setClustering(null);
        }

Here is the version that I currently use:

compile 'com.google.android.gms:play-services-maps:9.8.0' compile 'com.androidmapsextensions:android-maps-extensions:2.4.0'

1- Is there anyway to fix that memory leak from the library side? 2- For all your handlers, can you use this, that uses weak references for its handlers to avoid any memory leak?

maxime-kouemo avatar Sep 13 '17 16:09 maxime-kouemo

Could you prepare a SSCCE, so I can look into this issue? A pull request with an Activity or Fragment that shows it would be perfect. You may look into old ones like this as starting point.

mg6maciej avatar Sep 14 '17 07:09 mg6maciej

I wrote the project at work today, and you will be able to switch to google maps' map view to see what I am talking about. I have to wait until monday for my admin to check it before I can do the pull request (it is a compagny related work). Sorry for the incoming delay.

maxime-kouemo avatar Sep 14 '17 23:09 maxime-kouemo

Hi, I have just added a .zip file (here) of the project. Sorry for such a huge file, be assure that there is no security issue or compromising file in the .zip . It is the easiest way for me at this time of writing.

maxime-kouemo avatar Sep 21 '17 13:09 maxime-kouemo

Hi mg6maciej. Did you have the time to look it?

maxime-kouemo avatar Jan 29 '18 15:01 maxime-kouemo