Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

Android Dialog Memoery leak inside Fragment

I have used custom dialog inside Fragment.

if (dialogAuthorization == null) {
     dialogAuthorization = new Dialog(getActivity());
     dialogAuthorization.requestWindowFeature(Window.FEATURE_NO_TITLE);
     dialogAuthorization.setContentView(R.layout.dialog_sales_register_change_deposit);
}

My problem is I am using leak canary to check app performance.

But it shows below logs for leaking memory.

I am also dismissing dialog after my usage. but still, show a memory leak.

Anyone can help me with how to clear or properly destroy dialog for available to GC?.

01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ┬───
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │ GC Root: System class
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ├─ com.jmsc.jmscpostabapp.AppBaseActivity class
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Leaking: NO (FragmentSalesRegisterRConly↓ is not leaking and a class is never leaking)
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    ↓ static AppBaseActivity.objEpsonPrintEND
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ├─ com.jmsc.jmscpostabapp.ui.fragments.sales.FragmentSalesRegisterRConly instance
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Leaking: NO (Fragment#mFragmentManager is not null)
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    activity instance of com.jmsc.jmscpostabapp.ui.activity.HomeActivity with mDestroyed = false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    appContext instance of com.jmsc.jmscpostabapp.JMSCApplication
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    objBaseActivity instance of com.jmsc.jmscpostabapp.ui.activity.HomeActivity with mDestroyed = false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    objAct instance of com.jmsc.jmscpostabapp.ui.activity.HomeActivity with mDestroyed = false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Fragment.mTag=SALES REGISTER
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    ↓ FragmentSalesRegisterRConly.dialogAuthorization
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │                                  ~~~~~~~~~~~~~~~~~~~
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ├─ android.app.Dialog instance
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Leaking: UNKNOWN
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Retaining 19.9 kB in 376 objects
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    mContext instance of android.view.ContextThemeWrapper, wrapping activity com.jmsc.jmscpostabapp.ui.activity.
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    HomeActivity with mDestroyed = false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Dialog#mDecor is null
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    ↓ Dialog.mWindow
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │             ~~~~~~~
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ├─ com.android.internal.policy.PhoneWindow instance
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Leaking: UNKNOWN
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Retaining 19.7 kB in 371 objects
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    mContext instance of android.view.ContextThemeWrapper, wrapping activity com.jmsc.jmscpostabapp.ui.activity.
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    HomeActivity with mDestroyed = false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    Window#mDestroyed is false
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │    ↓ PhoneWindow.mDecor
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: │                  ~~~~~~
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ╰→ com.android.internal.policy.PhoneWindow$DecorView instance
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     Leaking: YES (ObjectWatcher was watching this because com.android.internal.policy.PhoneWindow$DecorView received
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     View#onDetachedFromWindow() callback)
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     Retaining 2.3 kB in 45 objects
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     key = 8133e6b0-f2ac-4a64-8c31-190aaad6e516
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     watchDurationMillis = 12486
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     retainedDurationMillis = 7212
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     View not part of a window view hierarchy
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     View.mAttachInfo is null (view detached)
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     View.mWindowAttachCount = 1
01-06 03:20:54.147 14985-15323/com.jmsc.jmscpostabapp D/LeakCanary: ?     mContext instance of android.view.ContextThemeWrapper, wrapping activity com.jmsc.jmscpostabapp.ui.activity.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...