1 package leakcanary
2 
3 import shark.AndroidMetadataExtractor
4 import shark.AndroidObjectInspectors
5 import shark.AndroidReferenceMatchers
6 import shark.FilteringLeakingObjectFinder
7 import shark.LeakingObjectFinder
8 import shark.MetadataExtractor
9 import shark.ObjectInspector
10 import shark.IgnoredReferenceMatcher
11 import shark.ReferenceMatcher
12 import shark.LibraryLeakReferenceMatcher
13 
14 data class HeapAnalysisConfig(
15 
16   /**
17    * Known patterns of references in the heap, added here either to ignore them
18    * ([IgnoredReferenceMatcher]) or to mark them as library leaks ([LibraryLeakReferenceMatcher]).
19    *
20    * When adding your own custom [LibraryLeakReferenceMatcher] instances, you'll most
21    * likely want to set [LibraryLeakReferenceMatcher.patternApplies] with a filter that checks
22    * for the Android OS version and manufacturer. The build information can be obtained by calling
23    * [shark.AndroidBuildMirror.fromHeapGraph].
24    *
25    * Defaults to [AndroidReferenceMatchers.appDefaults]
26    */
27   val referenceMatchers: List<ReferenceMatcher> = AndroidReferenceMatchers.appDefaults,
28 
29   /**
30    * List of [ObjectInspector] that provide LeakCanary with insights about objects found in the
31    * heap. You can create your own [ObjectInspector] implementations, and also add
32    * a [shark.AppSingletonInspector] instance created with the list of internal singletons.
33    *
34    * Defaults to [AndroidObjectInspectors.appDefaults]
35    */
36   val objectInspectors: List<ObjectInspector> = AndroidObjectInspectors.appDefaults,
37 
38   /**
39    * Extracts metadata from a hprof to be reported in [shark.HeapAnalysisSuccess.metadata].
40    * Called on a background thread during heap analysis.
41    *
42    * Defaults to [AndroidMetadataExtractor]
43    */
44   val metadataExtractor: MetadataExtractor = AndroidMetadataExtractor,
45 
46   /**
47    * Whether to compute the retained heap size, which is the total number of bytes in memory that
48    * would be reclaimed if the detected leaks didn't happen. This includes native memory
49    * associated to Java objects (e.g. Android bitmaps).
50    *
51    * Computing the retained heap size can slow down the analysis because it requires navigating
52    * from GC roots through the entire object graph, whereas [shark.HeapAnalyzer] would otherwise
53    * stop as soon as all leaking instances are found.
54    *
55    * Defaults to true.
56    */
57   val computeRetainedHeapSize: Boolean = true,
58 
59   /**
60    * Finds the objects that are leaking, for which LeakCanary will compute leak traces.
61    *
62    * Defaults to a [FilteringLeakingObjectFinder] that scans all objects in the heap dump and
63    * delegates the decision to [AndroidObjectInspectors.appLeakingObjectFilters].
64    */
65   val leakingObjectFinder: LeakingObjectFinder = FilteringLeakingObjectFinder(
66     AndroidObjectInspectors.appLeakingObjectFilters
67   ),
68 
69   /**
70    * Whether the first step after a heap dump should be to replace the content of all arrays with
71    * zeroes. This increases the overall processing time but limits the amount of time the heap
72    * dump exists on disk with potential PII.
73    */
74   val stripHeapDump: Boolean = false
75 )
76