Skip to content
🤔 Documentation issue? Report it


Package leakcanary


Name Summary
ActivityWatcher class ActivityWatcher(application: Application, reachabilityWatcher: ReachabilityWatcher) : InstallableWatcher
Expects activities to become weakly reachable soon after they receive the Activity.onDestroy callback.
AndroidDebugHeapDumper object AndroidDebugHeapDumper : HeapDumper
Dumps the Android heap using Debug.dumpHprofData.
AndroidDetectLeaksAssert class AndroidDetectLeaksAssert(detectLeaksInterceptor: DetectLeaksInterceptor = AndroidDetectLeaksInterceptor(), heapAnalysisReporter: HeapAnalysisReporter = NoLeakAssertionFailedError.throwOnApplicationLeaks()) : DetectLeaksAssert
Default DetectLeaksAssert implementation. Uses public helpers so you should be able to create our own implementation if needed.
AndroidDetectLeaksInterceptor class AndroidDetectLeaksInterceptor(instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation(), objectWatcher: ObjectWatcher = AppWatcher.objectWatcher, retainedDelayMillis: Long = AppWatcher.retainedDelayMillis) : DetectLeaksInterceptor
AndroidLeakFixes enum AndroidLeakFixes : Enum<AndroidLeakFixes>
A collection of hacks to fix leaks in the Android Framework and other Google Android libraries.
AppWatcher object AppWatcher
The 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 on objectWatcher to watch any other object that you expect to be unreachable.
BackgroundThreadHeapAnalyzer object BackgroundThreadHeapAnalyzer : EventListener
Starts heap analysis on a background HandlerThread when receiving a HeapDump event.
BackgroundTrigger class BackgroundTrigger(application: Application, analysisClient: HeapAnalysisClient, analysisExecutor: Executor, processInfo: ProcessInfo = ProcessInfo.Real, analysisCallback: (HeapAnalysisJob.Result) -> Unit = { result -> SharkLog.d { "$result" } })
Clock fun interface Clock
An interface to abstract the SystemClock.uptimeMillis() Android API in non Android artifacts.
ConditionalInterceptor class ConditionalInterceptor(delegate: HeapAnalysisInterceptor, evaluateCondition: (HeapAnalysisJob) -> Boolean) : HeapAnalysisInterceptor
An interceptor that runs only when evaluateCondition returns true.
DetectLeaksAfterTestSuccess class DetectLeaksAfterTestSuccess(tag: String = : TestRule
TestRule that invokes LeakAssertions.assertNoLeaks after the test successfully evaluates. Pay attention to where you set up this rule in the rule chain as you might detect different leaks (e.g. around vs wrapped by the activity rule). It’s also possible to use this rule several times in a rule chain.
DetectLeaksAssert fun interface DetectLeaksAssert
The interface for the implementation that LeakAssertions.assertNoLeaks delegates to. You can call DetectLeaksAssert.update to provide your own implementation.
DetectLeaksInterceptor fun interface DetectLeaksInterceptor
Decides whether to dump & analyze the heap to look for leaks in instrumentation tests. The implementation might block for a while to allow temporary leaks to be flushed out, as those aren’t that interesting to report and heap analysis increases test duration significantly.
EventListener fun interface EventListener
FragmentAndViewModelWatcher class FragmentAndViewModelWatcher(application: Application, reachabilityWatcher: ReachabilityWatcher) : InstallableWatcher
GcTrigger fun interface GcTrigger
GcTrigger is used to try triggering garbage collection and enqueuing KeyedWeakReference into the associated java.lang.ref.ReferenceQueue. The default implementation Default comes from AOSP.
GoodAndroidVersionInterceptor class GoodAndroidVersionInterceptor : HeapAnalysisInterceptor
HeapAnalysisClient class HeapAnalysisClient(heapDumpDirectoryProvider: () -> File, config: HeapAnalysisConfig, interceptors: List<HeapAnalysisInterceptor>)
HeapAnalysisConfig data class HeapAnalysisConfig(val referenceMatchers: List<ReferenceMatcher> = AndroidReferenceMatchers.appDefaults, val objectInspectors: List<ObjectInspector> = AndroidObjectInspectors.appDefaults, val metadataExtractor: MetadataExtractor = AndroidMetadataExtractor, val computeRetainedHeapSize: Boolean = true, val leakingObjectFinder: LeakingObjectFinder = FilteringLeakingObjectFinder( AndroidObjectInspectors.appLeakingObjectFilters ), val stripHeapDump: Boolean = false)
HeapAnalysisDecision sealed class HeapAnalysisDecision
HeapAnalysisInterceptor fun interface HeapAnalysisInterceptor
HeapAnalysisJob interface HeapAnalysisJob
A HeapAnalysisJob represents a single prepared request to analyze the heap. It cannot be executed twice.
HeapAnalysisReporter fun interface HeapAnalysisReporter
Reports the results of a heap analysis created by AndroidDetectLeaksAssert.
HeapDumper fun interface HeapDumper
InstallableWatcher interface InstallableWatcher
JobContext class JobContext(val starter: Class<*>? = null)
In memory store that can be used to store objects in a given HeapAnalysisJob instance. This is a simple MutableMap of String to Any, but with unsafe generics access.
KeyedWeakReference class KeyedWeakReference(referent: Any, val key: String, val description: String, val watchUptimeMillis: Long, referenceQueue: ReferenceQueue<Any>) : WeakReference<Any>
A weak reference used by ObjectWatcher to determine which objects become weakly reachable and which don’t. ObjectWatcher uses key to keep track of KeyedWeakReference instances that haven’t made it into the associated ReferenceQueue yet.
LazyForwardingEventListener class LazyForwardingEventListener(lazyEventListener: () -> EventListener) : EventListener
Forwards events to the EventListener provided by lazyEventListener which is evaluated lazily, when the first comes in.
LeakAssertions object LeakAssertions
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.
LeakCanaryProcess object LeakCanaryProcess
Used to determine whether the current process is the LeakCanary analyzer process. By depending on the leakcanary-android-process artifact instead of the leakcanary-android, LeakCanary will automatically run its analysis in a separate process.
LogcatEventListener object LogcatEventListener : EventListener
LogcatSharkLog class LogcatSharkLog : SharkLog.Logger
MinimumDiskSpaceInterceptor class MinimumDiskSpaceInterceptor(application: Application, minimumDiskSpaceBytes: Long, processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
MinimumElapsedSinceStartInterceptor class MinimumElapsedSinceStartInterceptor(minimumElapsedSinceStartMillis: Long = TimeUnit.SECONDS.toMillis(30), processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
MinimumMemoryInterceptor class MinimumMemoryInterceptor(application: Application, minimumRequiredAvailableMemoryBytes: Long, processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
NoLeakAssertionFailedError class NoLeakAssertionFailedError(val heapAnalysis: HeapAnalysisSuccess) : AssertionError
Thrown when using the NoLeakAssertionFailedError.throwOnApplicationLeaks HeapAnalysisReporter
NotificationEventListener object NotificationEventListener : EventListener
ObjectWatcher class ObjectWatcher(clock: Clock, checkRetainedExecutor: Executor, isEnabled: () -> Boolean = { true }) : ReachabilityWatcher
ObjectWatcher can be passed objects to watch. It will create KeyedWeakReference instances that reference watches objects, and check if those references have been cleared as expected on the checkRetainedExecutor executor. If not, these objects are considered retained and ObjectWatcher will then notify registered OnObjectRetainedListeners on that executor thread.
OncePerPeriodInterceptor class OncePerPeriodInterceptor(application: Application, periodMillis: Long = TimeUnit.DAYS.toMillis(1)) : HeapAnalysisInterceptor
Proceeds once per period (of time) and then cancels all follow up jobs until period has passed.
OnObjectRetainedListener fun interface OnObjectRetainedListener
Listener used by ObjectWatcher to report retained objects.
ProcessInfo interface ProcessInfo
ReachabilityWatcher fun interface ReachabilityWatcher
RemoteWorkManagerHeapAnalyzer object RemoteWorkManagerHeapAnalyzer : EventListener
When receiving a HeapDump event, starts a WorkManager worker that performs heap analysis in a dedicated :leakcanary process
RootViewWatcher class RootViewWatcher(reachabilityWatcher: ReachabilityWatcher) : InstallableWatcher
Expects root views to become weakly reachable soon after they are removed from the window manager.
SaveResourceIdsInterceptor class SaveResourceIdsInterceptor(resources: Resources) : HeapAnalysisInterceptor
Interceptor that saves the names of* entries and their associated int values to a static field that can then be read from the heap dump.
ScreenOffTrigger class ScreenOffTrigger(application: Application, analysisClient: HeapAnalysisClient, analysisExecutor: Executor, analysisCallback: (HeapAnalysisJob.Result) -> Unit = { result -> SharkLog.d { "$result" } })
ServiceWatcher class ServiceWatcher(reachabilityWatcher: ReachabilityWatcher) : InstallableWatcher
Expects services to become weakly reachable soon after they receive the Service.onDestroy callback.
SkipLeakDetection @Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.FUNCTION])
annotation class SkipLeakDetection(val message: String, val assertionTags: String)
Annotation for skipping leak detection in a UI test that calls LeakAssertions.assertNoLeaks. This annotation is useful to skip a leak detection in a test until the leaks are fixed.
TestDescriptionHolder object TestDescriptionHolder : TestRule
A TestRule that holds onto the test Description in a thread local while evaluating, making it possible to retrieve that test Description from the test thread via testDescription.
ToastEventListener object ToastEventListener : EventListener
TvEventListener object TvEventListener : EventListener
ViewLocationHolderLeakFix object ViewLocationHolderLeakFix
WorkManagerHeapAnalyzer object WorkManagerHeapAnalyzer : EventListener
When receiving a HeapDump event, starts a WorkManager worker that performs heap analysis.