Skip to content

Commit 4fef059

Browse files
author
Daniel Novak
committed
Add Square's LeakCanary
1 parent 4b8dd82 commit 4fef059

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

sample/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ android {
1313
}
1414

1515
compileOptions {
16+
encoding "UTF-8"
1617
sourceCompatibility JavaVersion.VERSION_1_7
1718
targetCompatibility JavaVersion.VERSION_1_7
1819
}
@@ -26,6 +27,8 @@ android {
2627

2728
dependencies {
2829
compile 'com.android.support:appcompat-v7:22.1.1'
30+
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
31+
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
2932
compile 'com.jakewharton:butterknife:5.1.2'
3033
compile project(':library')
3134
}

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<application
66
android:allowBackup="true"
77
android:icon="@mipmap/ic_launcher"
8+
android:name=".SampleApplication"
89
android:label="@string/app_name"
910
android:theme="@style/AppTheme" >
1011
<activity
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package eu.inloop.viewmodel.sample;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
6+
import com.squareup.leakcanary.LeakCanary;
7+
import com.squareup.leakcanary.RefWatcher;
8+
9+
public class SampleApplication extends Application {
10+
11+
private RefWatcher refWatcher;
12+
13+
@Override public void onCreate() {
14+
super.onCreate();
15+
refWatcher = LeakCanary.install(this);
16+
}
17+
18+
public static RefWatcher getRefWatcher(Context context) {
19+
SampleApplication application = (SampleApplication) context.getApplicationContext();
20+
return application.refWatcher;
21+
}
22+
23+
}

sample/src/main/java/eu/inloop/viewmodel/sample/fragment/UserListFragment.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
import android.widget.ListView;
1111
import android.widget.TextView;
1212

13+
import com.squareup.leakcanary.RefWatcher;
14+
1315
import java.util.ArrayList;
1416
import java.util.List;
1517

1618
import butterknife.ButterKnife;
1719
import butterknife.InjectView;
1820
import eu.inloop.viewmodel.base.ViewModelBaseFragment;
1921
import eu.inloop.viewmodel.sample.R;
22+
import eu.inloop.viewmodel.sample.SampleApplication;
2023
import eu.inloop.viewmodel.sample.viewmodel.UserListViewModel;
2124
import eu.inloop.viewmodel.sample.viewmodel.view.IUserListView;
2225

@@ -112,4 +115,13 @@ public void showLoading(float progress) {
112115
public void hideProgress() {
113116
mProgressView.setVisibility(View.GONE);
114117
}
118+
119+
@Override
120+
public void onDestroy() {
121+
super.onDestroy();
122+
123+
// watch for memory leaks
124+
RefWatcher refWatcher = SampleApplication.getRefWatcher(getActivity());
125+
refWatcher.watch(this);
126+
}
115127
}

0 commit comments

Comments
 (0)