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

BaseDialogFragment和BaseDialog内存泄漏 #34

Closed
sorrybeman opened this issue Nov 29, 2019 · 14 comments
Closed

BaseDialogFragment和BaseDialog内存泄漏 #34

sorrybeman opened this issue Nov 29, 2019 · 14 comments

Comments

@sorrybeman
Copy link

因为Builder需要在dismiss后还需要被引用,有没好的方法解决内存泄漏这个问题。

@sorrybeman
Copy link
Author

我的想法是在内部加个监听,手动去把它们置空,这样感觉会带来一系列的隐患。

@getActivity
Copy link
Owner

我在 Leaks 并没有捕捉内存泄漏的情况

@getActivity
Copy link
Owner

我建议你试一下最新的源码编译还会不会出现这个问题,我在之前的版本有修复过关于 Dialog 内存泄漏问题

@sorrybeman
Copy link
Author

  • 代码是最新的。我在activity持有DialogBuilder,在dismiss之后, BaseDialog和BaseDialogFragment显示内存泄漏。系统要回收Dialog和DialogFragment,而被持有的Builder又持有它们,所以泄漏了。
  • 上个版本的解决的内存泄漏问题,应该是监听器泄露的,感觉与我这种情况不同。你可以持有Builder类试一试,我看到Demo是没有去持有的,当然也没有必要持有。

@getActivity
Copy link
Owner

内存泄漏你是怎么用工具检测的

@sorrybeman
Copy link
Author

leakcanary 1.6.2

@getActivity
Copy link
Owner

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'

@getActivity
Copy link
Owner

你换成这个版本再试试

@sorrybeman
Copy link
Author

  • 换成的了 2.0,刚刚看到11.27发布了正式版。
├─ XXXFragmentLeaking: NO (Fragment#mFragmentManager is not null)
│    Fragment.mTag=XXX
│    ↓ XXXFragment.XXXDialogBuilder
│                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
├─ XXXDialog$BuilderLeaking: UNKNOWN
│    ↓ XXXDialog$Builder.mDialogFragment
│                                ~~~~~~~~~~~~~~~
╰→ XXX.widget.dialog.BaseDialogFragmentLeaking: YES (Fragment#mFragmentManager is null and ObjectWatcher was watching this)
​     key = b82a6f82-8bbc-452d-8cf0-be816378d1f3watchDurationMillis = 7714retainedDurationMillis = 2713

METADATA

Build.VERSION.SDK_INT: 24
Build.MANUFACTURER: samsung
LeakCanary version: 2.0
App process name: comXXX
Analysis duration: 8653 ms

@getActivity
Copy link
Owner

你换成这个版本再试试看

@sorrybeman
Copy link
Author

换成beta3不会报泄漏,这是为何?

@getActivity
Copy link
Owner

可能是旧版本的Bug

@sorrybeman
Copy link
Author

可能是旧版本的Bug
2.0正式版是最新的,这就奇怪了。那实际上代码本身是不会泄漏的吗。

@getActivity
Copy link
Owner

Leaks 本身也存在误报,但 Bug 会随着更新而越来越少的,所以要以最新版本为主。

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