Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to connect LeakCanary with KTP #418

Open
afaucogney opened this issue Aug 9, 2020 · 0 comments
Open

Trying to connect LeakCanary with KTP #418

afaucogney opened this issue Aug 9, 2020 · 0 comments

Comments

@afaucogney
Copy link

afaucogney commented Aug 9, 2020

LeakCanary detects leaks which belong to official Android/Jetpack lifecycles.

With KTP, we may define our own instances management system with a scope-tree.
When we open and close scopes, a lifecycle is then derived for every instance of the app. Nevertheless, dev can add code that trigger leaks, and even if the scope is closed and the instance is not injectable anymore, the instance is still there because of a leak.

LeakCanary supports custom lifecycle watcher, where we can tell it to watch if an instance will be soon garbage collected with :
AppWatcher.objectWatcher.watch(viewAdapter, "the view adapter should be destroyed")

Is there a way to retrieve all instances that belong to a scope at runtime ? To enable an automatic verification of the leak less instances ? that could be at the end looking like this ?

KTP.openScope(this).getScopedInstances().forEach {
    AppWatcher.objectWatcher.watch(it, "the instance ${it.instance} of the class ${it.class.name} should be destroyed")`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant