shark-android / shark / AndroidReferenceMatchers

AndroidReferenceMatchers

enum class AndroidReferenceMatchers

AndroidReferenceMatchers values add ReferenceMatcher instances to a global list via their add method. A ReferenceMatcher is either a IgnoredReferenceMatcher or a LibraryLeakReferenceMatcher.

AndroidReferenceMatchers is used to build the list of known references that cannot ever create leaks (via IgnoredReferenceMatcher) as well as the list of known leaks in the Android Framework and in manufacturer specific Android implementations.

This class is a work in progress. You can help by reporting leak traces that seem to be caused by the Android SDK, here: https://github.com/square/leakcanary/issues/new

We filter on SDK versions and Manufacturers because many of those leaks are specific to a given manufacturer implementation, they usually share their builds across multiple models, and the leaks eventually get fixed in newer versions.

Most app developers should use appDefaults. However, you can also use a subset of AndroidReferenceMatchers by creating an EnumSet that matches your needs and calling buildKnownReferences.

Enum Values

NameSummary
IREQUEST_FINISH_CALLBACK
ACTIVITY_CLIENT_RECORD__NEXT_IDLE
SPAN_CONTROLLER
MEDIA_SESSION_LEGACY_HELPER__SINSTANCE
TEXT_LINE__SCACHED
BLOCKING_QUEUE
INPUT_METHOD_MANAGER_IS_TERRIBLE
LAYOUT_TRANSITION
SPELL_CHECKER_SESSION
SPELL_CHECKER
ACTIVITY_CHOOSE_MODEL
MEDIA_PROJECTION_CALLBACK
SPEECH_RECOGNIZER
ACCOUNT_MANAGER
MEDIA_SCANNER_CONNECTION
USER_MANAGER__SINSTANCE
APP_WIDGET_HOST_CALLBACKS
AUDIO_MANAGER
EDITTEXT_BLINK_MESSAGEQUEUE
CONNECTIVITY_MANAGER__SINSTANCE
ACCESSIBILITY_NODE_INFO__MORIGINALTEXT
ASSIST_STRUCTURE
ACCESSIBILITY_ITERATORS
BIOMETRIC_PROMPT
MAGNIFIER
BACKDROP_FRAME_RENDERER__MDECORVIEW
VIEWLOCATIONHOLDER_ROOT
ACCESSIBILITY_NODE_ID_MANAGER
TEXT_TO_SPEECH
CONTROLLED_INPUT_CONNECTION_WRAPPER
TOAST_TN
APPLICATION_PACKAGE_MANAGER__HAS_SYSTEM_FEATURE_QUERY
SPEN_GESTURE_MANAGER
CLIPBOARD_UI_MANAGER__SINSTANCE
SEM_CLIPBOARD_MANAGER__MCONTEXT
CLIPBOARD_EX_MANAGER
SEM_EMERGENCY_MANAGER__MCONTEXT
SEM_PERSONA_MANAGER
SEM_APP_ICON_SOLUTION
AW_RESOURCE__SRESOURCES
TEXT_VIEW__MLAST_HOVERED_VIEW
PERSONA_MANAGER
RESOURCES__MCONTEXT
VIEW_CONFIGURATION__MCONTEXT
AUDIO_MANAGER__MCONTEXT_STATIC
ACTIVITY_MANAGER_MCONTEXT
STATIC_MTARGET_VIEW
MULTI_WINDOW_DECOR_SUPPORT__MWINDOW
GESTURE_BOOST_MANAGER
BUBBLE_POPUP_HELPER__SHELPER
LGCONTEXT__MCONTEXT
SMART_COVER_MANAGER
MAPPER_CLIENT
SYSTEM_SENSOR_MANAGER__MAPPCONTEXTIMPL
INSTRUMENTATION_RECOMMEND_ACTIVITY
DEVICE_POLICY_MANAGER__SETTINGS_OBSERVER
EXTENDED_STATUS_BAR_MANAGER
OEM_SCENE_CALL_BLOCKER
RAZER_TEXT_KEY_LISTENER__MCONTEXT
REFERENCES
FINALIZER_WATCHDOG_DAEMON
MAIN
LEAK_CANARY_THREAD
LEAK_CANARY_HEAP_DUMPER
LEAK_CANARY_INTERNAL
EVENT_RECEIVER__MMESSAGE_QUEUE

Companion Object Properties

NameSummary
appDefaultsval appDefaults: List<ReferenceMatcher>
HUAWEIconst val HUAWEI: String
ignoredReferencesOnlyval ignoredReferencesOnly: List<ReferenceMatcher>
Returns a list of ReferenceMatcher that only contains IgnoredReferenceMatcher and no LibraryLeakReferenceMatcher.
LENOVOconst val LENOVO: String
LGconst val LG: String
MEIZUconst val MEIZU: String
MOTOROLAconst val MOTOROLA: String
NVIDIAconst val NVIDIA: String
ONE_PLUSconst val ONE_PLUS: String
RAZERconst val RAZER: String
SAMSUNGconst val SAMSUNG: String
SHARPconst val SHARP: String
VIVOconst val VIVO: String

Companion Object Functions

NameSummary
buildKnownReferencesfun buildKnownReferences(referenceMatchers: Set<AndroidReferenceMatchers>): List<ReferenceMatcher>
Builds a list of ReferenceMatcher from the referenceMatchers set of AndroidReferenceMatchers.
ignoredInstanceFieldfun ignoredInstanceField(className: String, fieldName: String): IgnoredReferenceMatcher
Creates a IgnoredReferenceMatcher that matches a InstanceFieldPattern.
ignoredJavaLocalfun ignoredJavaLocal(threadName: String): IgnoredReferenceMatcher
Creates a IgnoredReferenceMatcher that matches a JavaLocalPattern.
instanceFieldLeakfun instanceFieldLeak(className: String, fieldName: String, description: String= "", patternApplies:AndroidBuildMirror.() -> Boolean = ALWAYS): LibraryLeakReferenceMatcher
Creates a LibraryLeakReferenceMatcher that matches a InstanceFieldPattern. [description](instance-field-leak.md#shark.AndroidReferenceMatchers.Companion$instanceFieldLeak(kotlin.String, kotlin.String, kotlin.String, kotlin.Function1((shark.AndroidBuildMirror, kotlin.Boolean)))/description) should convey what we know about this library leak.
nativeGlobalVariableLeakfun nativeGlobalVariableLeak(className: String, description: String= "", patternApplies:AndroidBuildMirror.() -> Boolean = ALWAYS): LibraryLeakReferenceMatcher
staticFieldLeakfun staticFieldLeak(className: String, fieldName: String, description: String= "", patternApplies:AndroidBuildMirror.() -> Boolean = ALWAYS): LibraryLeakReferenceMatcher
Creates a LibraryLeakReferenceMatcher that matches a StaticFieldPattern. [description](static-field-leak.md#shark.AndroidReferenceMatchers.Companion$staticFieldLeak(kotlin.String, kotlin.String, kotlin.String, kotlin.Function1((shark.AndroidBuildMirror, kotlin.Boolean)))/description) should convey what we know about this library leak.