Open maxxx opened 3 years ago
We definitely should beef up the documentation here.
So, your problem is that the PushyService is leaking, because the mqtt connection is still running and referencing it as a context instead of using the application context. You should reach out to them and ask them to fix it. I just filed something here: https://github.com/pushy-me/pushy-demo-android/issues/17
The updated config you used should work, and I think it did, however you excluded one path and LeakCanary found another path for that same leak. And it could find many other paths!
Your key issue here is that you don't want LeakCanary to track any PushyService instance. This is only documented in the changelog for now: https://square.github.io/leakcanary/changelog/#configuring-retained-object-detection
class DebugExampleApplication : ExampleApplication() {
override fun onCreate() {
super.onCreate()
val delegate = ReachabilityWatcher { watchedObject, description ->
if (watchedObject !is PushyService) {
AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description)
}
}
val watchersToInstall = AppWatcher.appDefaultWatchers(application, delegate)
AppWatcher.manualInstall(
application = application,
watchersToInstall = watchersToInstall
)
}
}
Similar issue here, where I need to exclude a single member-variable of a single class.
But I want to configure existing default watcher, instead of disabling default, and installing own custom watcher.
@pyricau Even if you "beef up the documentation" what I said is currently not supported, is it???
Being forced to do all that for a single member-variable seems to be far too much.
@pyricau Any update on how to "configure existing default watcher"?
Also, your online documentation seems to be down (at time of writting), hence I downloaded.
But could not find any answer yet.
You can install your own watcher, yes.
"can install your own watcher"
@pyricau Okay, I guessed you may know.
But for anyone else interested, with v2.9 (and maybe later) here is how:
import leakcanary.LeakCanary;
import shark.AndroidReferenceMatchers
// ...
// Fetch existing defaults.
val matchers = AndroidReferenceMatchers.appDefaults.toMutableList()
// Configure.
matchers += AndroidReferenceMatchers.instanceFieldLeak("my_package.MyClass", "myVariable")
// Save and/or apply changes.
LeakCanary.config = LeakCanary.config.copy(
referenceMatchers = matchers
)
Note that above's in
Kotlin
, because doing the same withJava
is far too complicated, hence consider Leak-canary to supportKotlin
only.That's no issue for me, I write in Kotlin and call it from Java.
Hello! I'm trying to exclude 3rd party lib memleak. This is the config:
And this is the memory leak report.
Problem - the memleak is still reported, I can find it in the "leaks" section (separate launcher icon). I haven't found any info about excluding leaks except https://square.github.io/leakcanary/recipes/#matching-known-library-leaks leakcanary v2.7