Ask Your Question
3

What is the process for omitting a class from being monitored by LeakCanary?

asked 2023-05-05 16:24:17 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-05 16:41:01 +0000

scrum gravatar image

To omit a class from being monitored by LeakCanary, you need to create a LeakCanaryExclusions class and add the class that needs to be excluded from monitoring.

Here are the steps to do it:

  1. Create a class that extends LeakCanaryExclusions.
class MyLeakCanaryExclusions : LeakCanaryExclusions {
    override fun excludeField(field: Field): Boolean {
        // Add logic here to exclude any fields from class
        // you want to exclude from LeakCanary monitoring
    }

    override fun excludeObject(className: String): Boolean {
        // Add logic here to exclude any class from LeakCanary monitoring
    }
}
  1. Set the exclusions to LeakCanary using the LeakCanary.config builder.
LeakCanary.config = LeakCanary.config.copy(
    exclusions = MyLeakCanaryExclusions())

That's it! Any class or field that has been excluded in the MyLeakCanaryExclusions class will not be monitored by LeakCanary.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-05 16:24:17 +0000

Seen: 11 times

Last updated: May 05 '23