Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Fix memory leak (#210)
Browse files Browse the repository at this point in the history
* Configure LeakCanary in the sample project
* Clean listener references in every single point where permission requests end
  • Loading branch information
Serchinastico authored Jun 21, 2018
1 parent e66d9f9 commit 5eaa0ae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dexter/src/main/java/com/karumi/dexter/DexterInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void onActivityReady(Activity activity) {
*/
void onActivityDestroyed() {
isRequestingPermission.set(false);
listener = EMPTY_LISTENER;
}

/**
Expand Down Expand Up @@ -322,6 +323,7 @@ private void checkMultiplePermissions(final MultiplePermissionsListener listener
}
isRequestingPermission.set(false);
listener.onPermissionsChecked(report);
DexterInstance.this.listener = EMPTY_LISTENER;
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void onCheckPermissionMoreThanOnceThenThrowException() {
}

@Test public void onPermissionFailedByRuntimeExceptionThenNotifiesListener() {
givenPermissionIsChecked(ANY_PERMISSION, PackageManager.PERMISSION_DENIED);
givenARuntimeExceptionIsThrownWhenPermissionIsChecked(ANY_PERMISSION);
givenShouldShowRationaleForPermission(ANY_PERMISSION);

Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.jakewharton:butterknife:8.6.0'
implementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
implementation project(':dexter')
androidTestImplementation 'com.android.support.test:runner:0.5'
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/>

<application
android:name=".SampleApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_logo_karumi"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.karumi.dexter.sample;

import android.app.Application;
import com.squareup.leakcanary.LeakCanary;

public class SampleApplication extends Application {

@Override public void onCreate() {
super.onCreate();
configureLeakCanary();
}

private void configureLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
return;
}
LeakCanary.install(this);
}
}

0 comments on commit 5eaa0ae

Please sign in to comment.