-
public class AppWatcherThe entry point API for using ObjectWatcher in an Android app. AppWatcher.objectWatcher is in charge of detecting retained objects, and AppWatcher is auto configured on app start to pass it activity and fragment instances. Call ObjectWatcher.watch on objectWatcher to watch any other object that you expect to be unreachable.
-
-
Field Summary
Fields Modifier and Type Field Description private volatile LongretainedDelayMillisprivate final ObjectWatcherobjectWatcherprivate final BooleanisInstalledpublic final static AppWatcherINSTANCE
-
Method Summary
Modifier and Type Method Description final UnitmanualInstall(Application application, Long retainedDelayMillis, List<InstallableWatcher> watchersToInstall)Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath). final UnitmanualInstall(Application application, Long retainedDelayMillis)Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath). final UnitmanualInstall(Application application)Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath). final List<InstallableWatcher>appDefaultWatchers(Application application, DeletableObjectReporter deletableObjectReporter)Creates a new list of default app InstallableWatcher, created with the passed in deletableObjectReporter (which defaults to objectWatcher). final LonggetRetainedDelayMillis()final UnitsetRetainedDelayMillis(Long retainedDelayMillis)final ObjectWatchergetObjectWatcher()The ObjectWatcher used by AppWatcher to detect retained objects. final BooleangetIsInstalled()-
-
Method Detail
-
manualInstall
@JvmOverloads() final Unit manualInstall(Application application, Long retainedDelayMillis, List<InstallableWatcher> watchersToInstall)
Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath).
In the main process, this method is automatically called with default parameter values on app startup. You can call this method directly to customize the installation, however you must first disable the automatic call by overriding the
leak_canary_watcher_auto_installboolean resource:<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="leak_canary_watcher_auto_install">false</bool> </resources>watchersToInstall can be customized to a subset of the default app watchers:
val watchersToInstall = AppWatcher.appDefaultWatchers(application) .filter { it !is RootViewWatcher } AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )watchersToInstall can also be customized to ignore specific instances (e.g. here ignoring leaks of BadSdkLeakingFragment):
val watchersToInstall = AppWatcher.appDefaultWatchers(application, ReachabilityWatcher { watchedObject, description -> if (watchedObject !is BadSdkLeakingFragment) { AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description) } }) AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )
-
manualInstall
@JvmOverloads() final Unit manualInstall(Application application, Long retainedDelayMillis)
Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath).
In the main process, this method is automatically called with default parameter values on app startup. You can call this method directly to customize the installation, however you must first disable the automatic call by overriding the
leak_canary_watcher_auto_installboolean resource:<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="leak_canary_watcher_auto_install">false</bool> </resources>watchersToInstall can be customized to a subset of the default app watchers:
val watchersToInstall = AppWatcher.appDefaultWatchers(application) .filter { it !is RootViewWatcher } AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )watchersToInstall can also be customized to ignore specific instances (e.g. here ignoring leaks of BadSdkLeakingFragment):
val watchersToInstall = AppWatcher.appDefaultWatchers(application, ReachabilityWatcher { watchedObject, description -> if (watchedObject !is BadSdkLeakingFragment) { AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description) } }) AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )
-
manualInstall
@JvmOverloads() final Unit manualInstall(Application application)
Enables usage of AppWatcher.objectWatcher which will expect passed in objects to become weakly reachable within retainedDelayMillis ms and if not will trigger LeakCanary (if LeakCanary is in the classpath).
In the main process, this method is automatically called with default parameter values on app startup. You can call this method directly to customize the installation, however you must first disable the automatic call by overriding the
leak_canary_watcher_auto_installboolean resource:<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="leak_canary_watcher_auto_install">false</bool> </resources>watchersToInstall can be customized to a subset of the default app watchers:
val watchersToInstall = AppWatcher.appDefaultWatchers(application) .filter { it !is RootViewWatcher } AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )watchersToInstall can also be customized to ignore specific instances (e.g. here ignoring leaks of BadSdkLeakingFragment):
val watchersToInstall = AppWatcher.appDefaultWatchers(application, ReachabilityWatcher { watchedObject, description -> if (watchedObject !is BadSdkLeakingFragment) { AppWatcher.objectWatcher.expectWeaklyReachable(watchedObject, description) } }) AppWatcher.manualInstall( application = application, watchersToInstall = watchersToInstall )
-
appDefaultWatchers
final List<InstallableWatcher> appDefaultWatchers(Application application, DeletableObjectReporter deletableObjectReporter)
Creates a new list of default app InstallableWatcher, created with the passed in deletableObjectReporter (which defaults to objectWatcher). Once installed, these watchers will pass in to deletableObjectReporter objects that they expect to become weakly reachable.
The passed in deletableObjectReporter should probably delegate to objectWatcher but can be used to filter out specific instances.
-
getRetainedDelayMillis
final Long getRetainedDelayMillis()
-
setRetainedDelayMillis
final Unit setRetainedDelayMillis(Long retainedDelayMillis)
-
getObjectWatcher
final ObjectWatcher getObjectWatcher()
The ObjectWatcher used by AppWatcher to detect retained objects. Only set when isInstalled is true.
-
getIsInstalled
final Boolean getIsInstalled()
-
-
-
-