我正在尝试实现 Chrome 自定义选项卡并通过 LeakCanary 检测内存泄漏。
除非我们添加另一个 Activity 层,否则演示应用程序似乎不会泄漏(即MainActivity
launch Activity2
,它绑定/取消绑定到自定义选项卡服务并启动 url -MainActivity
在演示应用程序中所做的一切)。
MainActivity 看起来像这样:
public class MainActivity extends Activity implements OnClickListener {
private Button mLaunchButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LeakCanary.install(getApplication());
setContentView(R.layout.main);
mLaunchButton = (Button) findViewById(R.id.launch_button);
mLaunchButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int viewId = v.getId();
if (viewId == R.id.launch_button) {
Intent intent = new Intent(getApplicationContext(), Activity2.class);
startActivity(intent);
}
}
}
从Activity2
to返回MainActivity
将导致此泄漏:
09-04 13:49:26.783 10456-12161/org.chromium.customtabsclient.example D/LeakCanary﹕ In org.chromium.customtabsclient.example:1.0:1.
09-04 13:49:26.783 10456-12161/org.chromium.customtabsclient.example D/LeakCanary﹕ * org.chromium.customtabsclient.Activity2 has leaked:
09-04 13:49:26.783 10456-12161/org.chromium.customtabsclient.example D/LeakCanary﹕ * GC ROOT android.support.customtabs.CustomTabsClient$1.val$callback (anonymous class extends android.support.customtabs.ICustomTabsCallback$Stub)
09-04 13:49:26.783 10456-12161/org.chromium.customtabsclient.example D/LeakCanary﹕ * references org.chromium.customtabsclient.Activity2$2.this$0 (anonymous class extends android.support.customtabs.CustomTabsCallback)
09-04 13:49:26.783 10456-12161/org.chromium.customtabsclient.example D/LeakCanary﹕ * leaks org.chromium.customtabsclient.Activity2 instance
https://gist.github.com/abvanpelt/ddbc732f31550b09fc27
我的问题是:这是演示应用程序中的错误吗?(也许unbindCustomTabsService()
缺少一些必要的拆解?)或者这是 Chrome 自定义标签库本身的错误?
谢谢你。