Skip to content
🤔 Documentation issue? Report it

//leakcanary/leakcanary/LeakCanary

LeakCanary

object LeakCanary

The entry point API for LeakCanary. LeakCanary builds on top of AppWatcher. AppWatcher notifies LeakCanary of retained instances, which in turns dumps the heap, analyses it and publishes the results.

LeakCanary can be configured by updating config.

Types

Name Summary
Config data class Config(val dumpHeap: Boolean = true, val dumpHeapWhenDebugging: Boolean = false, val retainedVisibleThreshold: Int = 5, val referenceMatchers: List<ReferenceMatcher> = AndroidReferenceMatchers.appDefaults, val objectInspectors: List<ObjectInspector> = AndroidObjectInspectors.appDefaults, onHeapAnalyzedListener: OnHeapAnalyzedListener = DefaultOnHeapAnalyzedListener.create(), val metadataExtractor: MetadataExtractor = AndroidMetadataExtractor, val computeRetainedHeapSize: Boolean = true, val maxStoredHeapDumps: Int = 7, val requestWriteExternalStoragePermission: Boolean = false, val leakingObjectFinder: LeakingObjectFinder = KeyedWeakReferenceFinder, val heapDumper: HeapDumper = AndroidDebugHeapDumper, val eventListeners: List<EventListener> = listOf( LogcatEventListener, ToastEventListener, LazyForwardingEventListener { if (InternalLeakCanary.formFactor == TV) TvEventListener else NotificationEventListener }, when { RemoteWorkManagerHeapAnalyzer.remoteLeakCanaryServiceInClasspath -> RemoteWorkManagerHeapAnalyzer WorkManagerHeapAnalyzer.validWorkManagerInClasspath -> WorkManagerHeapAnalyzer else -> BackgroundThreadHeapAnalyzer } ), val showNotifications: Boolean = true, useExperimentalLeakFinders: Boolean = false)
LeakCanary configuration data class. Properties can be updated via copy.

Functions

Name Summary
dumpHeap fun dumpHeap()
Immediately triggers a heap dump and analysis, if there is at least one retained instance tracked by AppWatcher.objectWatcher. If there are no retained instances then the heap will not be dumped and a notification will be shown instead.
newLeakDisplayActivityIntent fun newLeakDisplayActivityIntent(): Intent
Returns a new Intent that can be used to programmatically launch the leak display activity.
showLeakDisplayActivityLauncherIcon fun showLeakDisplayActivityLauncherIcon(showLauncherIcon: Boolean)
Dynamically shows / hides the launcher icon for the leak display activity. Note: you can change the default value by overriding the leak_canary_add_launcher_icon boolean resource:

Properties

Name Summary
config @JvmStatic
@Volatile
var config: LeakCanary.Config
The current LeakCanary configuration. Can be updated at any time, usually by replacing it with a mutated copy, e.g.: