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

Link copied to clipboard
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

Link copied to clipboard
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.

Link copied to clipboard
fun newLeakDisplayActivityIntent(): Intent

Returns a new Intent that can be used to programmatically launch the leak display activity.

Link copied to clipboard
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

Link copied to clipboard
var config: LeakCanary.Config

The current LeakCanary configuration. Can be updated at any time, usually by replacing it with a mutated copy, e.g.: