通过andriod studio提供的工具,分析Memory,获取一段内存情况之前,记得多点两下强制GC,以便分析的准确些。
分析结果如下图所示:
SubmitDialogFragment类写了如下代码
companion object { var submitDialogFragment: SubmitDialogFragment? = null @JvmStatic fun newInstance(): SubmitDialogFragment { val args = Bundle() submitDialogFragment = SubmitDialogFragment() submitDialogFragment!!.arguments = args return submitDialogFragment!! 童年的发现教案 } fun show( 牧马人 杨坤 fragmentManager: FragmentManager, confirmListener: ConfirmListener, content: String? = null ):SubmitDialogFragment { submitDialogFragment = newInstance() submitDialogFragment?.tContent(content) submitDialogFragment!!.mConfirmListener = confirmListener //设置普通样式,全屏风格 submitDialogFragment!!.tStyle(STYLE_NORMAL, R.style.Dialog_FullScreen) submitDialogFragment!!.show(fragmentManager, "") return submitDialogFragment!! } fun dismissDialog() { submitDialogFragment?.dismiss() } fun dialogIsVisible(): Boolean { return submitDialogFragment != null && submitDialogFragment!!.isVisible } }
查看build目录下生成的java字节码
public final class SubmitDialogFragment extends DialogFragment implements OnKeyListener, OnCancelListener { private View rootView; pr排除的近义词ivate String content; private SubmitDialogFragment.ConfirmListener mConfirmListener; @Nullable private static SubmitDialogFragment sarctanx等于什么ubmitDialogFragment; public static final SubmitDialogFragment.Companion Companion = new SubmitDialogFragment.Companion((DefaultConstructorMarker)null); private HashMap _$_findViewCache;
private static SubmitDialogFragment submitDialogFragment;
回忆一下背过的理论知识,可以作为GCRoot根其中之一就是静态成员变量。
把引用置为null,submitDialogFragment的实例就会被回收了
fun dismissDialog() { submitDialogFragment?.dismiss() //解决方案 submitDialogFragment = null }
本文地址:https://blog.csdn.net/weixin_38687303/article/details/112904726
本文发布于:2023-04-04 15:06:37,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/239355773b5e83a21620efb026c30cd0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:SubmitDialogFragment内存泄露.doc
本文 PDF 下载地址:SubmitDialogFragment内存泄露.pdf
留言与评论(共有 0 条评论) |