I'm attempting to implement Chrome Custom Tabs and detecting a memory leak through LeakCanary.
The demo application does not appear to leak unless we add another Activity layer (i.e. MainActivity
launches Activity2
, which binds/unbinds to the custom tab service and launches the url -- everything the MainActivity
does in the demo app).
MainActivity looks like this:
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);
}
}
}
Returning from Activity2
to MainActivity
will cause this leak:
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
My question is: is this a bug in the demo application? (Maybe unbindCustomTabsService()
is missing some needed teardown?) Or is this a bug in the Chrome Custom Tabs library itself?
Thank you.