Skip to content
🤔 Documentation issue? Report it

//leakcanary/leakcanary/AndroidLeakFixes

AndroidLeakFixes

enum AndroidLeakFixes : Enum<AndroidLeakFixes>

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

Entries

PERMISSION_CONTROLLER_MANAGER 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.
SPELL_CHECKER 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.
IMM_CUR_ROOT_VIEW 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.
IMM_FOCUSED_VIEW IMM_FOCUSED_VIEW()
Fix for https://code.google.com/p/android/issues/detail?id=171190 .
VIEW_LOCATION_HOLDER 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
ACTIVITY_MANAGER ACTIVITY_MANAGER()
Samsung added a static mContext field to ActivityManager, holding a reference to the activity.
LAST_HOVERED_VIEW LAST_HOVERED_VIEW()
mLastHoveredView is a static field in TextView that leaks the last hovered view.
BUBBLE_POPUP BUBBLE_POPUP()
A static helper for EditText bubble popups leaks a reference to the latest focused view.
SAMSUNG_CLIPBOARD_MANAGER 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.
CONNECTIVITY_MANAGER 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.
ACCESSIBILITY_NODE_INFO 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
FLUSH_HANDLER_THREADS 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.
USER_MANAGER 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.
TEXT_LINE_POOL TEXT_LINE_POOL()
This flushes the TextLine pool when an activity is destroyed, to prevent memory leaks.
MEDIA_SESSION_LEGACY_HELPER 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

Types

Name Summary
Companion object Companion

Properties

Name Summary
name val name: String
ordinal val ordinal: Int