Skip to content
🤔 Documentation issue? Report it

//leakcanary-repo/leakcanary/AndroidLeakFixes

AndroidLeakFixes

[androidJvm]\ enum AndroidLeakFixes : Enum<AndroidLeakFixes>

A collection of hacks to fix leaks in the Android Framework and other Google Android libraries.

Entries

MEDIA_SESSION_LEGACY_HELPER [androidJvm]
MEDIA_SESSION_LEGACY_HELPER
MediaSessionLegacyHelper is a static singleton and did not use the application context. Introduced in android-5.0.1_r1, fixed in Android 5.1.0_r1. https://github.com/android/platform_frameworks_base/commit/9b5257c9c99c4cb541d8e8e78fb04f008b1a9091
TEXT_LINE_POOL [androidJvm]
TEXT_LINE_POOL
This flushes the TextLine pool when an activity is destroyed, to prevent memory leaks.
USER_MANAGER [androidJvm]
USER_MANAGER
Obtaining the UserManager service ends up calling the hidden UserManager.get() method which stores the context in a singleton UserManager instance and then stores that instance in a static field.
FLUSH_HANDLER_THREADS [androidJvm]
FLUSH_HANDLER_THREADS
HandlerThread instances keep local reference to their last handled message after recycling it. That message is obtained by a dialog which sets on an OnClickListener on it and then never recycles it, expecting it to be garbage collected but it ends up being held by the HandlerThread.
ACCESSIBILITY_NODE_INFO [androidJvm]
ACCESSIBILITY_NODE_INFO
Until API 28, AccessibilityNodeInfo has a mOriginalText field that was not properly cleared when instance were put back in the pool. Leak introduced here: https://android.googlesource.com/platform/frameworks/base/+/193520e3dff5248ddcf8435203bf99d2ba667219%5E%21/core/java/android/view/accessibility/AccessibilityNodeInfo.java
CONNECTIVITY_MANAGER [androidJvm]
CONNECTIVITY_MANAGER
ConnectivityManager has a sInstance field that is set when the first ConnectivityManager instance is created. ConnectivityManager has a mContext field. When calling activity.getSystemService(Context.CONNECTIVITY_SERVICE) , the first ConnectivityManager instance is created with the activity context and stored in sInstance. That activity context then leaks forever.
SAMSUNG_CLIPBOARD_MANAGER [androidJvm]
SAMSUNG_CLIPBOARD_MANAGER
ClipboardUIManager is a static singleton that leaks an activity context. This fix makes sure the manager is called with an application context.
BUBBLE_POPUP [androidJvm]
BUBBLE_POPUP
A static helper for EditText bubble popups leaks a reference to the latest focused view.
LAST_HOVERED_VIEW [androidJvm]
LAST_HOVERED_VIEW
mLastHoveredView is a static field in TextView that leaks the last hovered view.
ACTIVITY_MANAGER [androidJvm]
ACTIVITY_MANAGER
Samsung added a static mContext field to ActivityManager, holding a reference to the activity.
VIEW_LOCATION_HOLDER [androidJvm]
VIEW_LOCATION_HOLDER
In Android P, ViewLocationHolder has an mRoot field that is not cleared in its clear() method. Introduced in https://github.com/aosp-mirror/platform_frameworks_base/commit/86b326012813f09d8f1de7d6d26c986a909d
IMM_FOCUSED_VIEW [androidJvm]
IMM_FOCUSED_VIEW
Fix for https://code.google.com/p/android/issues/detail?id=171190 .
IMM_CUR_ROOT_VIEW [androidJvm]
IMM_CUR_ROOT_VIEW
When an activity is destroyed, the corresponding ViewRootImpl instance is released and ready to be garbage collected. Some time after that, ViewRootImpl#W receives a windowfocusChanged() callback, which it normally delegates to ViewRootImpl which in turn calls InputMethodManager#onPreWindowFocus which clears InputMethodManager#mCurRootView.
SPELL_CHECKER [androidJvm]
SPELL_CHECKER
Every editable TextView has an Editor instance which has a SpellChecker instance. SpellChecker is in charge of displaying the little squiggle spans that show typos. SpellChecker starts a SpellCheckerSession as needed and then closes it when the TextView is detached from the window. A SpellCheckerSession is in charge of communicating with the spell checker service (which lives in another process) through TextServicesManager.
PERMISSION_CONTROLLER_MANAGER [androidJvm]
PERMISSION_CONTROLLER_MANAGER
PermissionControllerManager stores the first context it’s initialized with forever. Sometimes it’s an Activity context which then leaks after Activity is destroyed.

Types

Name Summary
Companion [androidJvm]
object Companion

Functions

Name Summary
valueOf [androidJvm]
fun valueOf(value: String): AndroidLeakFixes
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
values [androidJvm]
fun values(): Array<AndroidLeakFixes>
Returns an array containing the constants of this enum type, in the order they’re declared.

Properties

Name Summary
name [androidJvm]
val name: String
ordinal [androidJvm]
val ordinal: Int