Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fix Memory leak caused by duplicated add in LocationListener list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jaumeolba authored and tobrun committed Feb 5, 2016
1 parent 8e5862b commit 026e6a7
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public Location getLastLocation() {
* @param locationListener LocationListener
*/
public void addLocationListener(@NonNull LocationListener locationListener) {
this.locationListeners.add(locationListener);
if(!this.locationListeners.contains(locationListener)){
this.locationListeners.add(locationListener);
}
}

/**
Expand Down

0 comments on commit 026e6a7

Please sign in to comment.