如何从LeakCanary中排除课程? [英] How can I exclude a class from LeakCanary?

查看:206
本文介绍了如何从LeakCanary中排除课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这样做:

ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults()
                .clazz("androidx.lifecycle.ReportFragment")
                .reason("Very annoying report fragment leak that isn't a leak apparently")
                .alwaysExclude()
                .build();
        LeakCanary
                .refWatcher(context)
                .listenerServiceClass(DisplayLeakService.class)
                .excludedRefs(excludedRefs)
                .watchDelay(10, TimeUnit.SECONDS)
                .buildAndInstall();

但是我仍然得到ReportFragment was never GCed but no leak found.

我的一项活动也得到了这一点,我不知道该如何处理这些no leak found消息.

I also get that for one of my activities, no I idea what to do about these no leak found messages.

当前使用的是LeakCanary 1.6.3

current using LeakCanary 1.6.3

推荐答案

我发现了这一点;我以为我可以尝试

I found this; I thought I might try it

这按预期工作. 我们不知道在执行堆转储和分析之前是否排除了泄漏.完成此操作后,默认行为是显示带有[Excluded]作为前缀的通知.这使用户知道LeakCanary已完成.如果根本没有反馈,您将无法知道泄漏金丝雀是否已制成.可以说这是比没有反馈更好的用户体验.

This is working as expected. We can't know if a leak is excluded prior to performing the heap dump and analysis. Once we've done that, the default behavior is to display a notification with [Excluded] as a prefix. This lets users know that LeakCanary is done. If there was no feedback at all, you wouldn't have any way to know whether leak canary is done or not. This is arguably a better user experience than no feedback at all.

您可以通过提供自己的com.squareup.leakcanary.AbstractAnalysisResultService子类来自定义此行为,而不是使用默认的com.squareup.leakcanary.DisplayLeakService

You can customize this behavior by providing your own subclass of com.squareup.leakcanary.AbstractAnalysisResultService rather than using the default com.squareup.leakcanary.DisplayLeakService

这篇关于如何从LeakCanary中排除课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆