Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CountryCodeDialog Leaked Activity #316

Closed
stefanJi opened this issue May 30, 2019 · 2 comments
Closed

CountryCodeDialog Leaked Activity #316

stefanJi opened this issue May 30, 2019 · 2 comments

Comments

@stefanJi
Copy link

Leak Info:

* EXCLUDED LEAK.
* xxx.loginregister.activity.RegisterActivity has leaked:
* thread HandlerThread.!(<Java Local>)! (named 'TbsLogReportThread')
* ↳ Message.!(obj)! , matching exclusion field android.os.Message#obj
* ↳ CountryCodeDialog$3.!(val$context)! (anonymous implementation of android.content.DialogInterface$OnCancelListener)
* ↳ RegisterActivity

* Reference Key: d9181538-bcb0-4526-8bc6-8610ac7c5697
* Device: Xiaomi Xiaomi Mi Note 3 jason
* Android Version: 8.1.0 API: 27 LeakCanary: 1.6.1 26145bf
* Durations: watch=41455ms, gc=259ms, heap dump=5881ms, analysis=16281ms

* Details:
* Instance of android.os.HandlerThread
|   static $class$dexClassDefIndex = 2826
|   static $class$iFields = 1902684440
|   static $classOverhead = byte[208]@1900514505 (0x71478cc9)
|   static $class$dexTypeIndex = 5339
|   static $class$objectSizeAllocFastPath = 152
|   static $class$vtable = null
|   static $class$superClass = java.lang.Thread
|   static $class$name = "android.os.HandlerThread"
|   static $class$objectSize = 148
|   static $class$sFields = 0
|   static $class$status = 11
|   static $class$dexCache = java.lang.DexCache@1899375384 (0x71362b18)
|   static $class$shadow$_klass_ = java.lang.Class
|   static $class$ifTable = java.lang.Object[2]@1899425288 (0x7136ee08)
|   static $class$methods = 1903800300
|   static $class$classFlags = 0
|   static $class$shadow$_monitor_ = 536870912
|   static $class$numReferenceInstanceFields = 2
|   static $class$componentType = null
|   static $class$referenceInstanceOffsets = -1073741824
|   static $class$numReferenceStaticFields = 0
|   static $class$extData = null
|   static $class$clinitThreadId = 0
|   static $class$primitiveType = 131072
|   static $class$virtualMethodsOffset = 2
|   static $class$accessFlags = 524289
|   static $class$copiedMethodsOffset = 9
|   static $class$classSize = 332
|   static $class$classLoader = null
|   mHandler = null
|   mLooper = android.os.Looper@316943936 (0x12e42e40)
|   mPriority = 0
|   mTid = 6334
|   blocker = null
|   blockerLock = java.lang.Object@325844120 (0x136bfc98)
|   contextClassLoader = dalvik.system.PathClassLoader@317218936 (0x12e86078)
|   daemon = false
|   eetop = 0
|   group = java.lang.ThreadGroup@1893761920 (0x70e08380)
|   inheritableThreadLocals = null
|   inheritedAccessControlContext = java.security.AccessControlContext@325844128 (0x136bfca0)
|   lock = java.lang.Object@325844136 (0x136bfca8)
|   name = "TbsLogReportThread"
|   nativeParkEventPointer = 0
|   nativePeer = 3498031616
|   parkBlocker = null
|   parkState = 1
|   priority = 5
|   single_step = false
|   stackSize = 0
|   started = true
|   stillborn = false
|   target = null
|   threadLocalRandomProbe = 0
|   threadLocalRandomSecondarySeed = 0
|   threadLocalRandomSeed = 0
|   threadLocals = java.lang.ThreadLocal$ThreadLocalMap@325844144 (0x136bfcb0)
|   threadQ = null
|   threadStatus = 0
|   tid = 21528
|   uncaughtExceptionHandler = null
|   shadow$_klass_ = android.os.HandlerThread
|   shadow$_monitor_ = 0
* Instance of android.os.Message
|   static $class$dexClassDefIndex = 5455
|   static $class$iFields = 1902683676
|   static $classOverhead = byte[124]@1899373769 (0x713624c9)
|   static $class$dexTypeIndex = 5455
|   static $class$objectSizeAllocFastPath = 64
|   static $class$vtable = null
|   static $class$superClass = java.lang.Object
|   static $class$name = "android.os.Message"
|   static $class$objectSize = 64
|   static $class$sFields = 1902683528
|   static $class$status = 11
|   static $class$dexCache = java.lang.DexCache@1899375384 (0x71362b18)
|   static FLAG_ASYNCHRONOUS = 2
|   static sPoolSize = 29
|   static $class$shadow$_klass_ = java.lang.Class
|   static $class$ifTable = java.lang.Object[2]@1899426304 (0x7136f200)
|   static $class$methods = 1903797160
|   static $class$classFlags = 0
|   static $class$shadow$_monitor_ = 536870912
|   static sPool = android.os.Message@316941920 (0x12e42660)
|   static $class$numReferenceInstanceFields = 7
|   static CREATOR = android.os.Message$1@1899426328 (0x7136f218)
|   static $class$componentType = null
|   static $class$referenceInstanceOffsets = 127
|   static $class$numReferenceStaticFields = 3
|   static gCheckRecycle = true
|   static $class$extData = null
|   static $class$clinitThreadId = 0
|   static $class$primitiveType = 131072
|   static $class$virtualMethodsOffset = 13
|   static FLAG_IN_USE = 1
|   static $class$accessFlags = 524305
|   static $class$copiedMethodsOffset = 33
|   static $class$classSize = 281
|   static FLAGS_TO_CLEAR_ON_COPY_FROM = 1
|   static sPoolSync = java.lang.Object@1899375680 (0x71362c40)
|   static $class$classLoader = null
|   static MAX_POOL_SIZE = 50
|   arg1 = 0
|   arg2 = 0
|   callback = null
|   data = null
|   flags = 0
|   monitorInfo = android.os.BaseLooper$MessageMonitorInfo@325843440 (0x136bf9f0)
|   next = null
|   obj = com.hbb20.CountryCodeDialog$3@325843528 (0x136bfa48)
|   replyTo = null
|   sendingUid = -1
|   target = android.app.Dialog$ListenersHandler@325843544 (0x136bfa58)
|   what = 68
|   when = 0
|   shadow$_klass_ = android.os.Message
|   shadow$_monitor_ = 0
* Instance of com.hbb20.CountryCodeDialog$3
|   static $class$dexClassDefIndex = 872
|   static $class$iFields = 3345786152
|   static $classOverhead = byte[52]@322657489 (0x133b5cd1)
|   static $class$dexTypeIndex = 2753
|   static $class$objectSizeAllocFastPath = 16
|   static $class$vtable = null
|   static $class$superClass = java.lang.Object
|   static $class$name = null
|   static $class$objectSize = 16
|   static $class$sFields = 0
|   static $class$status = 11
|   static $class$dexCache = java.lang.DexCache@322621320 (0x133acf88)
|   static $class$shadow$_klass_ = java.lang.Class
|   static $class$ifTable = java.lang.Object[2]@323502760 (0x134842a8)
|   static $class$methods = 3345786192
|   static $class$classFlags = 0
|   static $class$shadow$_monitor_ = 0
|   static $class$numReferenceInstanceFields = 2
|   static $class$componentType = null
|   static $class$referenceInstanceOffsets = 3
|   static $class$numReferenceStaticFields = 0
|   static $class$extData = null
|   static $class$clinitThreadId = 6264
|   static $class$primitiveType = 131072
|   static $class$virtualMethodsOffset = 1
|   static $class$accessFlags = 524304
|   static $class$copiedMethodsOffset = 2
|   static $class$classSize = 176
|   static $class$classLoader = dalvik.system.PathClassLoader@317218936 (0x12e86078)
|   val$codePicker = com.hbb20.CountryCodePicker@325713072 (0x1369fcb0)
|   val$context = xxx.loginregister.activity.RegisterActivity@325713968 (0x136a0030)
|   shadow$_klass_ = com.hbb20.CountryCodeDialog$3
|   shadow$_monitor_ = 0

* Excluded Refs:
| Field: android.os.Message.obj
| Field: android.os.Message.next
| Field: android.os.Message.target
| Field: android.view.inputmethod.InputMethodManager.mNextServedView
| Field: android.view.inputmethod.InputMethodManager.mServedView
| Field: android.view.inputmethod.InputMethodManager.mServedInputConnection
| Field: android.view.inputmethod.InputMethodManager.mCurRootView
| Field: android.accounts.AccountManager$AmsTask$Response.this$1
| Field: android.view.Choreographer$FrameDisplayEventReceiver.mMessageQueue (always)
| Thread:FinalizerWatchdogDaemon (always)
| Thread:main (always)
| Thread:LeakCanary-Heap-Dump (always)
| Class:java.lang.ref.WeakReference (always)
| Class:java.lang.ref.SoftReference (always)
| Class:java.lang.ref.PhantomReference (always)
| Class:java.lang.ref.Finalizer (always)
| Class:java.lang.ref.FinalizerReference (always)

I think is hideKeyboard leaked activity ?

dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialogInterface) {
        hideKeyboard(context);
        if (codePicker.getDialogEventsListener() != null) {
            codePicker.getDialogEventsListener().onCcpDialogCancel(dialogInterface);
        }
    }
});
private static void hideKeyboard(Context context) {
    if (context instanceof Activity) {
        Activity activity = (Activity) context;
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        //Find the currently focused view, so we can grab the correct window token from it.
        View view = activity.getCurrentFocus();
        //If no view currently has focus, create a new one, just so we can grab a window token from it
        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);

Should use ApplicationContext ?

@hbb20
Copy link
Owner

hbb20 commented Jun 30, 2019

@stefanJi , thank you for posting. Looks like final context was a possible culprit. I have tried a possible fix by dismissing the dialog and setting them null on detach of CCP view to release the reference.

It will be in next release. If you find leak in next version, please feel free to report.

hbb20 added a commit that referenced this issue Jul 1, 2019
@hbb20
Copy link
Owner

hbb20 commented Aug 4, 2019

Thank you for reporting. We just released a new version v2.3.0 with the possible fix. Please check and let us know if it does not work as expected.

@hbb20 hbb20 closed this as completed Aug 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants