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

是否需要在BaseFragment 的 ondestroyView里面移除mRootView #50

Open
taixiang opened this issue Aug 23, 2017 · 5 comments
Open

Comments

@taixiang
Copy link

No description provided.

@taixiang
Copy link
Author

hello,在BaseFragment 的 onCreateView里

ViewGroup parent = (ViewGroup) mRootView.getParent();
        if (parent != null) {
            parent.removeView(mRootView);
        }

有这段移除rootview的但是一直没有执行到,请问是否需要把这段父布局移除rootview的代码移到 ondestroyView里面

@taixiang taixiang changed the title 是否需要在BaseFragment 的 ondestroyView 是否需要在BaseFragment 的 ondestroyView里面移除mRootView Aug 23, 2017
@Rukey7
Copy link
Owner

Rukey7 commented Aug 23, 2017

不用,销毁的时候mRootView也会销毁

@taixiang
Copy link
Author

我的场景是viewpager + fragment,有rootview的复用满足了需求,个人比较好奇rootview在什么时候销毁的 , 对应的Fragment ondestroy走了,rootview依然存在的 , viewpager用的FragmentStatePagerAdapter

@Rukey7
Copy link
Owner

Rukey7 commented Aug 25, 2017

按我的理解,fragment的生命周期由FragmentStatePagerAdapter控制,在FragmentStatePagerAdapter里保存了你添加的每个fragment,虽然调用了ondestroy,但是fragment对象并没有被销毁,所以rootview依然存在

@jiaowenzheng
Copy link

这种写法,在fragment 嵌套中 Leakcanary 会一直报内存泄漏。

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

3 participants