标签:leakcanary 内存泄露
public class MyApp extends Application {
public static RefWatcher getRefWatcher(Context context) {
MyApp application = (MyApp) context
.getApplicationContext();
return application.refWatcher;
}
private RefWatcher refWatcher;
@Override
public void onCreate() {
super.onCreate();
refWatcher = LeakCanary.install(this);
}
}
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Box box = new Box();//来自官方的例子
Cat schrodingerCat = new Cat();
box.hiddenCat = schrodingerCat;
Docker.container = box;
MyApp.getRefWatcher(this).watch(schrodingerCat);
}
}
class Cat {
}
class Box {
Cat hiddenCat;
}
class Docker {
static Box container;
}
# 结果
*
*
标签:leakcanary 内存泄露
原文地址:http://blog.csdn.net/cheyiliu/article/details/45866145