summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaumeolba <jaumeolba@gmail.com>2016-01-26 13:40:37 +0100
committerTobrun <tobrun@mapbox.com>2016-02-05 10:59:50 +0100
commit026e6a75600f7109828fc33ff97b117a3a5090a7 (patch)
tree999c5b0076a43b6a225f55fa55bbe9300a6de2df
parent8e5862bd5d7038d35ffbc485e807d24b04ba5e0a (diff)
downloadqtlocation-mapboxgl-026e6a75600f7109828fc33ff97b117a3a5090a7.tar.gz
Fix Memory leak caused by duplicated add in LocationListener list
The addLocationListener method didn't check if the LocationListener was already in the list. From MapView, if we call setMyLocationEnabled(true), it adds a LocationListener and onResume adds the same LocationListener again, but is just removed by onPause. So LocationListener is added twice but removed just once, so LocationServices singleton keeps an instance of the the LocationListener that is never released.
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
index 74a68c3722..ac2ab64076 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java
@@ -117,7 +117,9 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
* @param locationListener LocationListener
*/
public void addLocationListener(@NonNull LocationListener locationListener) {
- this.locationListeners.add(locationListener);
+ if(!this.locationListeners.contains(locationListener)){
+ this.locationListeners.add(locationListener);
+ }
}
/**