Skip to content
🤔 Documentation issue? Report it


Package shark


Name Summary
AnalyzeCommand class AnalyzeCommand : CliktCommand
AndroidBuildMirror class AndroidBuildMirror(val manufacturer: String, val sdkInt: Int, val id: String)
Caches values from the android.os.Build class in the heap dump. Retrieve a cached instances via fromHeapGraph.
AndroidMetadataExtractor object AndroidMetadataExtractor : MetadataExtractor
AndroidObjectInspectors enum AndroidObjectInspectors : Enum<AndroidObjectInspectors> , ObjectInspector
A set of default ObjectInspectors that knows about common AOSP and library classes.
AndroidReferenceMatchers enum AndroidReferenceMatchers : Enum<AndroidReferenceMatchers>
AndroidReferenceMatchers values add ReferenceMatcher instances to a global list via their add method. A ReferenceMatcher is either a IgnoredReferenceMatcher or a LibraryLeakReferenceMatcher.
AndroidResourceIdNames class AndroidResourceIdNames
AndroidServices object AndroidServices
ApplicationLeak data class ApplicationLeak(val leakTraces: List<LeakTrace>) : Leak
A leak found by HeapAnalyzer in your application.
AppSingletonInspector class AppSingletonInspector(singletonClasses: String) : ObjectInspector
Inspector that automatically marks instances of the provided class names as not leaking because they’re app wide singletons.
ByteArraySourceProvider class ByteArraySourceProvider(byteArray: ByteArray) : DualSourceProvider
CloseableHeapGraph interface CloseableHeapGraph : HeapGraph, Closeable
A HeapGraph that should be closed after being used.
ConstantMemoryMetricsDualSourceProvider class ConstantMemoryMetricsDualSourceProvider(realSourceProvider: DualSourceProvider) : DualSourceProvider
Captures IO read metrics without using much memory.
DeobfuscateHprofCommand class DeobfuscateHprofCommand : CliktCommand
DualSourceProvider interface DualSourceProvider : StreamingSourceProvider, RandomAccessSourceProvider
Both a StreamingSourceProvider and a RandomAccessSourceProvider
DumpProcessCommand class DumpProcessCommand : CliktCommand
FileSourceProvider class FileSourceProvider(file: File) : DualSourceProvider
FilteringLeakingObjectFinder class FilteringLeakingObjectFinder(filters: List<FilteringLeakingObjectFinder.LeakingObjectFilter>) : LeakingObjectFinder
Finds the objects that are leaking by scanning all objects in the heap dump and delegating the decision to a list of FilteringLeakingObjectFinder.LeakingObjectFilter
GcRoot sealed class GcRoot
A GcRoot as identified by HprofRecord.HeapDumpRecord.GcRootRecord in the heap dump.
GraphContext class GraphContext
In memory store that can be used to store objects in a given HeapGraph instance. This is a simple MutableMap of String to Any, but with unsafe generics access.
HeapAnalysis sealed class HeapAnalysis : Serializable
The result of an analysis performed by HeapAnalyzer, either a HeapAnalysisSuccess or a HeapAnalysisFailure. This class is serializable however there are no guarantees of forward compatibility.
HeapAnalysisException class HeapAnalysisException(cause: Throwable) : RuntimeException
HeapAnalysisFailure data class HeapAnalysisFailure(val heapDumpFile: File, val createdAtTimeMillis: Long, val dumpDurationMillis: Long = DUMP_DURATION_UNKNOWN, val analysisDurationMillis: Long, val exception: HeapAnalysisException) : HeapAnalysis
The analysis performed by HeapAnalyzer did not complete successfully.
HeapAnalysisSuccess data class HeapAnalysisSuccess(val heapDumpFile: File, val createdAtTimeMillis: Long, val dumpDurationMillis: Long = DUMP_DURATION_UNKNOWN, val analysisDurationMillis: Long, val metadata: Map<String, String>, val applicationLeaks: List<ApplicationLeak>, val libraryLeaks: List<LibraryLeak>, val unreachableObjects: List<LeakTraceObject>) : HeapAnalysis
The result of a successful heap analysis performed by HeapAnalyzer.
HeapAnalyzer class HeapAnalyzer(listener: OnAnalysisProgressListener)
Analyzes heap dumps to look for leaks.
HeapDumpRule class HeapDumpRule : ExternalResource
HeapField class HeapField(val declaringClass: HeapObject.HeapClass, val name: String, val value: HeapValue)
Represents a static field or an instance field.
HeapGraph interface HeapGraph
Enables navigation through the heap graph of objects.
HeapObject sealed class HeapObject
An object in the heap dump.
HeapValue class HeapValue(val graph: HeapGraph, val holder: ValueHolder)
Represents a value in the heap dump, which can be an object reference or a primitive type.
HprofDeobfuscator class HprofDeobfuscator
Converts a Hprof file to another file with deobfuscated class and field names.
HprofHeader data class HprofHeader(val heapDumpTimestamp: Long = System.currentTimeMillis(), val version: HprofVersion = HprofVersion.ANDROID, val identifierByteSize: Int = 4)
Represents the header metadata of a Hprof file.
HprofHeapGraph class HprofHeapGraph : CloseableHeapGraph
A HeapGraph that reads from an Hprof file indexed by HprofIndex.
HprofIndex class HprofIndex
An index on a Hprof file. See openHeapGraph.
HprofPrimitiveArrayStripper class HprofPrimitiveArrayStripper
Converts a Hprof file to another file with all primitive arrays replaced with arrays of zeroes, which can be useful to remove PII. Char arrays are handled slightly differently because 0 would be the null character so instead these become arrays of ‘?’.
HprofRecord sealed class HprofRecord
A Hprof record. These data structure map 1:1 with how records are written in hprof files.
HprofRecordReader class HprofRecordReader
Reads hprof content from an Okio BufferedSource.
HprofRecordTag enum HprofRecordTag : Enum<HprofRecordTag>
HprofVersion enum HprofVersion : Enum<HprofVersion>
Supported hprof versions
HprofWriter class HprofWriter : Closeable
Generates Hprof files.
HprofWriterHelper class HprofWriterHelper(writer: HprofWriter) : Closeable
IgnoredReferenceMatcher class IgnoredReferenceMatcher(val pattern: ReferencePattern) : ReferenceMatcher
IgnoredReferenceMatcher should be used to match references that cannot ever create leaks. The shortest path finder will never go through matching references.
InteractiveCommand class InteractiveCommand : CliktCommand
JvmTestHeapDumper object JvmTestHeapDumper
KeyedWeakReferenceFinder object KeyedWeakReferenceFinder : LeakingObjectFinder
Finds all objects tracked by a KeyedWeakReference, ie all objects that were passed to
Leak sealed class Leak : Serializable
A leak found by HeapAnalyzer, either an ApplicationLeak or a LibraryLeak.
LeakingObjectFinder fun interface LeakingObjectFinder
Finds the objects that are leaking, for which Shark will compute leak traces.
LeakTrace data class LeakTrace(val gcRootType: LeakTrace.GcRootType, val referencePath: List<LeakTraceReference>, val leakingObject: LeakTraceObject) : Serializable
The best strong reference path from a GC root to the leaking object. "Best" here means the shortest prioritized path. A large number of distinct paths can generally be found leading to a leaking object. Shark prioritizes paths that don’t go through known LibraryLeakReferenceMatcher (because those are known to create leaks so it’s more interesting to find other paths causing leaks), then it prioritize paths that don’t go through java local gc roots (because those are harder to reason about). Taking those priorities into account, finding the shortest path means there are less LeakTraceReference that can be suspected to cause the leak.
LeakTraceObject data class LeakTraceObject(val type: LeakTraceObject.ObjectType, val className: String, val labels: Set<String>, val leakingStatus: LeakTraceObject.LeakingStatus, val leakingStatusReason: String, val retainedHeapByteSize: Int?, val retainedObjectCount: Int?) : Serializable
LeakTraceReference data class LeakTraceReference(val originObject: LeakTraceObject, val referenceType: LeakTraceReference.ReferenceType, val owningClassName: String, val referenceName: String) : Serializable
A LeakTraceReference represents an origin LeakTraceObject and either a reference from that object to the LeakTraceObject in the next LeakTraceReference in LeakTrace.referencePath, or to LeakTrace.leakingObject if this is the last LeakTraceReference in LeakTrace.referencePath.
LibraryLeak data class LibraryLeak(val leakTraces: List<LeakTrace>, val pattern: ReferencePattern, val description: String) : Leak
A leak found by HeapAnalyzer, where the only path to the leaking object required going through a reference matched by pattern, as provided to a LibraryLeakReferenceMatcher instance. This is a known leak in library code that is beyond your control.
LibraryLeakReferenceMatcher data class LibraryLeakReferenceMatcher(val pattern: ReferencePattern, val description: String = "", val patternApplies: (HeapGraph) -> Boolean = { true }) : ReferenceMatcher
LibraryLeakReferenceMatcher should be used to match references in library code that are known to create leaks and are beyond your control. The shortest path finder will only go through matching references after it has exhausted references that don’t match, prioritizing finding an application leak over a known library leak. Library leaks will be reported as LibraryLeak instead of ApplicationLeak.
MetadataExtractor fun interface MetadataExtractor
Extracts metadata from a hprof to be reported in HeapAnalysisSuccess.metadata.
ObjectInspector fun interface ObjectInspector
Provides LeakCanary with insights about objects (classes, instances and arrays) found in the heap. inspect will be called for each object that LeakCanary wants to know more about. The implementation can then use the provided ObjectReporter to provide insights for that object.
ObjectInspectors enum ObjectInspectors : Enum<ObjectInspectors> , ObjectInspector
A set of default ObjectInspectors that knows about common JDK objects.
ObjectReporter class ObjectReporter(val heapObject: HeapObject)
Enables ObjectInspector implementations to provide insights on heapObject, which is an object (class, instance or array) found in the heap.
OnAnalysisProgressListener fun interface OnAnalysisProgressListener
Reports progress from the HeapAnalyzer as they occur, as Step values.
OnHprofRecordListener fun interface OnHprofRecordListener
Listener passed in to StreamingHprofReader.readRecords, gets notified for each HprofRecord found in the heap dump which types is in the set of the recordTypes parameter passed to StreamingHprofReader.readRecords.
OnHprofRecordTagListener fun interface OnHprofRecordTagListener
Listener passed in to StreamingHprofReader.readRecords, gets notified for each HprofRecordTag found in the heap dump.
PrimitiveType enum PrimitiveType : Enum<PrimitiveType>
A primitive type in the prof.
ProguardMapping class ProguardMapping
ProguardMappingHelper class ProguardMappingHelper(proguardMapping: ProguardMapping)
ProguardMappingReader class ProguardMappingReader(proguardMappingInputStream: InputStream)
RandomAccessHprofReader class RandomAccessHprofReader : Closeable
Reads records in a Hprof source, one at a time with a specific position and size. Call openReaderFor to obtain a new instance.
RandomAccessSource interface RandomAccessSource : Closeable
RandomAccessSourceProvider fun interface RandomAccessSourceProvider
Can open RandomAccessSource instances.
ReferenceMatcher sealed class ReferenceMatcher
Used to pattern match known patterns of references in the heap, either to ignore them (IgnoredReferenceMatcher) or to mark them as library leaks (LibraryLeakReferenceMatcher).
ReferencePattern sealed class ReferencePattern : Serializable
A pattern that will match references for a given ReferenceMatcher.
SharkCliCommand class SharkCliCommand : CliktCommand
SharkLog object SharkLog
Central Logger for all Shark artifacts. Set logger to change where these logs go.
StreamingHprofReader class StreamingHprofReader
Reads the entire content of a Hprof source in one fell swoop. Call readerFor to obtain a new instance.
StreamingRecordReaderAdapter class StreamingRecordReaderAdapter(streamingHprofReader: StreamingHprofReader)
Wraps a StreamingHprofReader to provide a higher level API that streams HprofRecord instances.
StreamingSourceProvider fun interface StreamingSourceProvider
Can open Source instances.
StripHprofCommand class StripHprofCommand : CliktCommand
ThrowingCancelableFileSourceProvider class ThrowingCancelableFileSourceProvider(file: File, throwIfCanceled: Runnable) : DualSourceProvider
A DualSourceProvider that invokes throwIfCanceled before every read, allowing cancellation of IO based work built on top by throwing an exception.
ValueHolder sealed class ValueHolder
A value in the heap dump, which can be a ReferenceHolder or a primitive type.


Name Summary
asHprofBytes fun List<HprofRecord>.asHprofBytes(): DualSourceProvider
create fun ProguardMapping.create(block: ProguardMappingHelper.() -> Unit): ProguardMapping
dump fun File.dump(block: HprofWriterHelper.() -> Unit)
fun dump(hprofHeader: HprofHeader = HprofHeader(), block: HprofWriterHelper.() -> Unit): DualSourceProvider
dumpToBytes fun dumpToBytes(hprofHeader: HprofHeader = HprofHeader(), block: HprofWriterHelper.() -> Unit): ByteArray
main fun main(args: Array<String>)


Name Summary
hexIdentityHashCode val HeapObject.HeapInstance.hexIdentityHashCode: String?
The system identity hashCode represented as hex, or null if it couldn’t be found. This is the string identifier you see when calling Object.toString() at runtime on a class that does not override its hashCode() method, e.g. com.example.MyThing@6bd57cf
identityHashCode val HeapObject.HeapInstance.identityHashCode: Int?
The system identity hash code, or null if it couldn’t be found.