Skip to content
🤔 Documentation issue? Report it

//leakcanary-repo/leakcanary

Package-level declarations

Types

Name Summary
ActivityWatcher [androidJvm]
class ActivityWatcher(application: Application, deletableObjectReporter: DeletableObjectReporter) : InstallableWatcher
Expects activities to become weakly reachable soon after they receive the Activity.onDestroy callback.
AndroidDebugHeapDumper [androidJvm]
object AndroidDebugHeapDumper : HeapDumper
Dumps the Android heap using Debug.dumpHprofData.
AndroidDetectLeaksAssert [androidJvm]
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 [androidJvm]
class AndroidDetectLeaksInterceptor(instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation(), retainedObjectTracker: RetainedObjectTracker = AppWatcher.objectWatcher, retainedDelayMillis: Long = AppWatcher.retainedDelayMillis) : DetectLeaksInterceptor
AndroidDeviceTempHeapDumpDirectoryProvider [androidJvm]
class AndroidDeviceTempHeapDumpDirectoryProvider(heapDumpDirectoryName: String) : HeapDumpDirectoryProvider
AndroidLeakFixes [androidJvm]
enum AndroidLeakFixes : Enum<AndroidLeakFixes>
A collection of hacks to fix leaks in the Android Framework and other Google Android libraries.
AppWatcher [androidJvm]
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 ObjectWatcher.watch on objectWatcher to watch any other object that you expect to be unreachable.
AppWatcherStartupInitializer [androidJvm]
class AppWatcherStartupInitializer : Initializer<AppWatcherStartupInitializer>
BackgroundThreadHeapAnalyzer [androidJvm]
object BackgroundThreadHeapAnalyzer : EventListener
Starts heap analysis on a background HandlerThread when receiving a HeapDump event.
BackgroundTrigger [androidJvm]
class BackgroundTrigger(application: Application, analysisClient: HeapAnalysisClient, analysisExecutor: Executor, processInfo: ProcessInfo = ProcessInfo.Real, analysisCallback: (HeapAnalysisJob.Result) -> Unit = { result -> SharkLog.d { "$result" } })
ConditionalInterceptor [androidJvm]
class ConditionalInterceptor(delegate: HeapAnalysisInterceptor, evaluateCondition: (HeapAnalysisJob) -> Boolean) : HeapAnalysisInterceptor
An interceptor that runs only when evaluateCondition returns true.
DatetimeFormattedHeapDumpFileProvider [jvm]
class DatetimeFormattedHeapDumpFileProvider(heapDumpDirectoryProvider: HeapDumpDirectoryProvider, dateProvider: () -> Date = { Date() }, prefixProvider: () -> String = { "" }, suffixProvider: () -> String = { "" }) : HeapDumpFileProvider
DefaultDelayDeletableObjectReporter [jvm]
class DefaultDelayDeletableObjectReporter(defaultDelay: Duration, delayedReporter: DelayedDeletableObjectReporter) : DeletableObjectReporter
DelayedDeletableObjectReporter [jvm]
class DelayedDeletableObjectReporter(deletableObjectReporter: TriggeredDeletableObjectReporter, delayedExecutor: DelayedExecutor)
DelayedExecutor [jvm]
fun interface DelayedExecutor
DeletableObjectReporter [jvm]
fun interface DeletableObjectReporter
DetectLeaksAfterTestSuccess [androidJvm]
class DetectLeaksAfterTestSuccess(tag: String = DetectLeaksAfterTestSuccess::class.java.simpleName) : 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 [androidJvm]
fun interface DetectLeaksAssert
The interface for the implementation that LeakAssertions.assertNoLeaks delegates to. You can call DetectLeaksAssert.update to provide your own implementation.
DetectLeaksInterceptor [androidJvm]
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.
DumpingRepeatingScenarioObjectGrowthDetector [jvm]
class DumpingRepeatingScenarioObjectGrowthDetector(objectGrowthDetector: ObjectGrowthDetector, heapDumpFileProvider: HeapDumpFileProvider, heapDumper: HeapDumper, heapDumpStorageStrategy: HeapDumpStorageStrategy) : RepeatingScenarioObjectGrowthDetector
A RepeatingScenarioObjectGrowthDetector suitable for junit based automated tests that can dump the heap.
EventListener [androidJvm]
fun interface EventListener
FinalizingInProcessGcTrigger [jvm]
object FinalizingInProcessGcTrigger : GcTrigger
A GcTrigger that attempts to perform a GC by invoking the corresponding JDK API then waiting and then running finalization. Based on FinalizationTest in AOSP.
FragmentAndViewModelWatcher [androidJvm]
class FragmentAndViewModelWatcher(application: Application, deletableObjectReporter: DeletableObjectReporter) : InstallableWatcher
Expects:
GcTrigger [jvm]
fun interface GcTrigger
GoodAndroidVersionInterceptor [androidJvm]
class GoodAndroidVersionInterceptor : HeapAnalysisInterceptor
HeapAnalysisClient [androidJvm]
class HeapAnalysisClient(heapDumpDirectoryProvider: () -> File, config: HeapAnalysisConfig, interceptors: List<HeapAnalysisInterceptor>)
HeapAnalysisConfig [androidJvm]
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, val proguardMappingProvider: () -> ProguardMapping? = { null })
HeapAnalysisDecision [androidJvm]
sealed class HeapAnalysisDecision
HeapAnalysisInterceptor [androidJvm]
fun interface HeapAnalysisInterceptor
HeapAnalysisJob [androidJvm]
interface HeapAnalysisJob
A HeapAnalysisJob represents a single prepared request to analyze the heap. It cannot be executed twice.
HeapAnalysisReporter [androidJvm]
fun interface HeapAnalysisReporter
Reports the results of a heap analysis created by AndroidDetectLeaksAssert.
HeapDumpDirectoryProvider [jvm]
fun interface HeapDumpDirectoryProvider
HeapDumper [jvm]
fun interface HeapDumper
HeapDumpFileProvider [jvm]
fun interface HeapDumpFileProvider
HeapDumpStorageStrategy [jvm]
interface HeapDumpStorageStrategy
HotSpotHeapDumper [jvm]
object HotSpotHeapDumper : HeapDumper
InstallableWatcher [androidJvm]
interface InstallableWatcher
JobContext [androidJvm]
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 [jvm]
class KeyedWeakReference(referent: Any, val key: String, val description: String, val watchUptimeMillis: Long, referenceQueue: ReferenceQueue<Any>) : WeakReference<Any>
A weak reference used by ReferenceQueueRetainedObjectTracker to determine which objects become weakly reachable and which don’t. ReferenceQueueRetainedObjectTracker uses key to keep track of KeyedWeakReference instances that haven’t made it into the associated ReferenceQueue yet.
LazyForwardingEventListener [androidJvm]
class LazyForwardingEventListener(lazyEventListener: () -> EventListener) : EventListener
Forwards events to the EventListener provided by lazyEventListener which is evaluated lazily, when the first comes in.
LeakAssertions [androidJvm]
object LeakAssertions
LeakCanary [androidJvm]
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 [androidJvm]
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 [androidJvm]
object LogcatEventListener : EventListener
LogcatSharkLog [androidJvm]
class LogcatSharkLog : SharkLog.Logger
MinimumDiskSpaceInterceptor [androidJvm]
class MinimumDiskSpaceInterceptor(application: Application, minimumDiskSpaceBytes: Long, processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
MinimumElapsedSinceStartInterceptor [androidJvm]
class MinimumElapsedSinceStartInterceptor(minimumElapsedSinceStartMillis: Long = TimeUnit.SECONDS.toMillis(30), processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
MinimumMemoryInterceptor [androidJvm]
class MinimumMemoryInterceptor(application: Application, minimumRequiredAvailableMemoryBytes: Long, processInfo: ProcessInfo = ProcessInfo.Real) : HeapAnalysisInterceptor
NoLeakAssertionFailedError [androidJvm]
class NoLeakAssertionFailedError(val heapAnalysis: HeapAnalysisSuccess) : AssertionError
Thrown when using the NoLeakAssertionFailedError.throwOnApplicationLeaks HeapAnalysisReporter
NotificationEventListener [androidJvm]
object NotificationEventListener : EventListener
ObjectGrowthWarmupHeapDumper [jvm]
class ObjectGrowthWarmupHeapDumper(objectGrowthDetector: ObjectGrowthDetector, delegate: HeapDumper, androidHeap: Boolean) : HeapDumper
OncePerPeriodInterceptor [androidJvm]
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 [jvm]
fun interface OnObjectRetainedListener
Listener used by ReferenceQueueRetainedObjectTracker to report retained objects.
PlumberStartupInitializer [androidJvm]
class PlumberStartupInitializer : Initializer<PlumberStartupInitializer>
ProcessInfo [androidJvm]
interface ProcessInfo
ReferenceQueueRetainedObjectTracker [jvm]
class ReferenceQueueRetainedObjectTracker(clock: UptimeClock, onObjectRetainedListener: OnObjectRetainedListener) : RetainedObjectTracker, TriggeredDeletableObjectReporter
ReferenceQueueRetainedObjectTracker can be passed objects to expectDeletionOnTriggerFor. It will create KeyedWeakReference instances that reference tracked objects, and check if those references have been cleared as expected. If not, these objects are considered retained and ReferenceQueueRetainedObjectTracker will then notify registered OnObjectRetainedListeners. ReferenceQueueRetainedObjectTracker is thread safe.
RemoteWorkManagerHeapAnalyzer [androidJvm]
object RemoteWorkManagerHeapAnalyzer : EventListener
When receiving a HeapDump event, starts a WorkManager worker that performs heap analysis in a dedicated :leakcanary process
RepositoryRootHeapDumpDirectoryProvider [jvm]
class RepositoryRootHeapDumpDirectoryProvider(heapDumpDirectoryName: String) : HeapDumpDirectoryProvider
RetainedObjectTracker [jvm]
interface RetainedObjectTracker
Helper util for tracking retained objects.
RootViewWatcher [androidJvm]
class RootViewWatcher(deletableObjectReporter: DeletableObjectReporter, rootViewFilter: RootViewWatcher.Filter = WindowTypeFilter(watchDismissedDialogs = false)) : InstallableWatcher
Expects root views to become weakly reachable soon after they are removed from the window manager.
SaveResourceIdsInterceptor [androidJvm]
class SaveResourceIdsInterceptor(resources: Resources) : HeapAnalysisInterceptor
Interceptor that saves the names of R.id.* entries and their associated int values to a static field that can then be read from the heap dump.
ScreenOffTrigger [androidJvm]
class ScreenOffTrigger(application: Application, analysisClient: HeapAnalysisClient, analysisExecutor: Executor, analysisCallback: (HeapAnalysisJob.Result) -> Unit = { result -> SharkLog.d { "$result" } })
ServiceWatcher [androidJvm]
class ServiceWatcher(deletableObjectReporter: DeletableObjectReporter) : InstallableWatcher
Expects services to become weakly reachable soon after they receive the Service.onDestroy callback.
SkipLeakDetection [androidJvm]
@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.
TargetContextHeapDumpDirectoryProvider [androidJvm]
class TargetContextHeapDumpDirectoryProvider(heapDumpDirectoryName: String) : HeapDumpDirectoryProvider
TestDescriptionHolder [jvm]
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.
TestHeapDumpFileProvider [jvm]
class TestHeapDumpFileProvider(heapDumpDirectoryProvider: HeapDumpDirectoryProvider) : HeapDumpFileProvider
TestName [jvm]
interface TestName
TestNameProvider [jvm]
object TestNameProvider
ToastEventListener [androidJvm]
object ToastEventListener : EventListener
TrackedObjectReachability [jvm]
interface TrackedObjectReachability
TriggeredDeletableObjectReporter [jvm]
interface TriggeredDeletableObjectReporter
Tracks deletion of target objects, marking them retained on trigger.
TvEventListener [androidJvm]
object TvEventListener : EventListener
UiAutomatorShellFileDeleter [androidJvm]
object UiAutomatorShellFileDeleter
UiAutomatorShellHeapDumper [androidJvm]
class UiAutomatorShellHeapDumper(withGc: Boolean, dumpedAppPackageName: String) : HeapDumper
UptimeClock [jvm]
fun interface UptimeClock
An interface to abstract the clock to get the system uptime.
ViewLocationHolderLeakFix [androidJvm]
object ViewLocationHolderLeakFix
WorkManagerHeapAnalyzer [androidJvm]
object WorkManagerHeapAnalyzer : EventListener
When receiving a HeapDump event, starts a WorkManager worker that performs heap analysis.

Functions

Name Summary
filteringInstances [jvm]
inline fun <T> DeletableObjectReporter.filteringInstances(crossinline apply: (T) -> Boolean): DeletableObjectReporter
Creates a wrapper around DeletableObjectReporter that will run any instance of T by apply to decide whether to forward to DeletableObjectReporter.expectDeletionFor calls. Objects that do not extend T will always be forwarded.
forAndroidInProcess [androidJvm]
fun HeapDumper.Companion.forAndroidInProcess(): AndroidDebugHeapDumper
forJvmInProcess [jvm]
fun HeapDumper.Companion.forJvmInProcess(): HotSpotHeapDumper
forUiAutomatorAsShell [androidJvm]
fun HeapDumper.Companion.forUiAutomatorAsShell(withGc: Boolean, dumpedAppPackageName: String = InstrumentationRegistry.getInstrumentation().targetContext.packageName): UiAutomatorShellHeapDumper
inProcess [jvm]
fun GcTrigger.Companion.inProcess(): FinalizingInProcessGcTrigger
repeatingAndroidInProcessScenario [androidJvm]
fun HeapDiff.Companion.repeatingAndroidInProcessScenario(objectGrowthDetector: ObjectGrowthDetector = ObjectGrowthDetector.forAndroidHeap(), heapDumpDirectoryProvider: HeapDumpDirectoryProvider = TargetContextHeapDumpDirectoryProvider( heapDumpDirectoryName = "heap_dumps_object_growth" ), heapDumper: HeapDumper = HeapDumper.forAndroidInProcess() .withGc(gcTrigger = GcTrigger.inProcess()) .withDetectorWarmup(objectGrowthDetector, androidHeap = true), heapDumpStorageStrategy: HeapDumpStorageStrategy = HeapDumpStorageStrategy.DeleteOnHeapDumpClose()): RepeatingScenarioObjectGrowthDetector
Creates a RepeatingScenarioObjectGrowthDetector suitable for Android in process tests, such as Espresso tests.
repeatingJvmInProcessScenario [jvm]
fun HeapDiff.Companion.repeatingJvmInProcessScenario(objectGrowthDetector: ObjectGrowthDetector = ObjectGrowthDetector.forJvmHeap(), heapDumpDirectoryProvider: HeapDumpDirectoryProvider = RepositoryRootHeapDumpDirectoryProvider( "heap_dumps_object_growth" ), heapDumper: HeapDumper = HeapDumper.forJvmInProcess() .withGc(gcTrigger = GcTrigger.inProcess()) .withDetectorWarmup(objectGrowthDetector, androidHeap = false), heapDumpStorageStrategy: HeapDumpStorageStrategy = HeapDumpStorageStrategy.DeleteOnHeapDumpClose()): RepeatingScenarioObjectGrowthDetector
Creates a RepeatingScenarioObjectGrowthDetector suitable for JVM in process tests.
repeatingUiAutomatorScenario [androidJvm]
fun HeapDiff.Companion.repeatingUiAutomatorScenario(objectGrowthDetector: ObjectGrowthDetector = ObjectGrowthDetector.forAndroidHeap(), dumpedAppPackageName: String = InstrumentationRegistry.getInstrumentation().targetContext.packageName, heapDumpDirectoryProvider: HeapDumpDirectoryProvider = AndroidDeviceTempHeapDumpDirectoryProvider( heapDumpDirectoryName = "heap_dumps_object_growth_$dumpedAppPackageName" ), heapDumper: HeapDumper = HeapDumper.forUiAutomatorAsShell( withGc = true, dumpedAppPackageName = dumpedAppPackageName ), heapDumpStorageStrategy: HeapDumpStorageStrategy = HeapDumpStorageStrategy.DeleteOnHeapDumpClose { heapDumpFile -> UiAutomatorShellFileDeleter.deleteFileUsingShell(heapDumpFile) }): RepeatingScenarioObjectGrowthDetector
Creates a RepeatingScenarioObjectGrowthDetector suitable for Android UI Automator tests.
withDetectorWarmup [jvm]
fun HeapDumper.withDetectorWarmup(objectGrowthDetector: ObjectGrowthDetector, androidHeap: Boolean): HeapDumper
withGc [jvm]
fun HeapDumper.withGc(gcTrigger: GcTrigger = GcTrigger.inProcess()): HeapDumper