Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to solve memory leak #240

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ buildscript {
mavenCentral()
maven { url "https://maven.google.com" }
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}

}

allprojects {
repositories {
mavenCentral()
maven { url "https://maven.google.com" }
jcenter()
google()
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 14 10:52:55 BST 2017
#Fri Jun 22 08:51:40 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'

apply plugin: 'com.github.dcendents.android-maven'

version smartLocationVersion
group 'io.nlopez.smartlocation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static class LocationControl {

private static final Map<Context, LocationProvider> MAPPING = new WeakHashMap<>();

private final SmartLocation smartLocation;
private SmartLocation smartLocation;
private LocationParams params;
private LocationProvider provider;
private boolean oneFix;
Expand Down Expand Up @@ -212,6 +212,13 @@ public void start(OnLocationUpdatedListener listener) {
public void stop() {
provider.stop();
}

public void destroy() {
provider.destroy();
provider = null;
params = null;
smartLocation = null;
}
}

public static class GeocodingControl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface LocationProvider {

Location getLastLocation();

void destroy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public void onActivityUpdated(DetectedActivity detectedActivity) {
public interface LocationBasedOnActivityListener {
public LocationParams locationParamsForActivity(DetectedActivity detectedActivity);
}

@Override
public void destroy() {
locationProvider.destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ public Location getLastLocation() {
return null;
}

@Override
public void destroy() {
context = null;
listener = null;
googlePlayServicesListener = null;
serviceListener = null;
}

@Override
public ServiceConnectionListener getServiceListener() {
return serviceListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public void stop() {
shouldStart = false;
}

@Override
public void destroy() {
provider.destroy();
context = null;
listener = null;
}

@Override
public Location getLastLocation() {
return provider.getLastLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {

}

@Override
public void destroy() {
mContext = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ void fallbackProvider() {
}
}

@Override
public void destroy() {
context = null;
if (currentProvider != null) {
currentProvider.destroy();
}
}

/**
* Builder class for the {@link MultiFallbackProvider}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void simulateFailure() {
listener.onConnectionFailed();
}
}

@Override
public void destroy() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public Location getLastLocation() {
public void fakeEmitLocation(Location location) {
listener.onLocationUpdated(location);
}

@Override
public void destroy() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,10 @@ public Location getLastLocation() {
public void fakeEmit(Location location) {
mListener.onLocationUpdated(location);
}

@Override
public void destroy() {

}
}
}