简体   繁体   中英

What does removing a Fragment in Android really do?

What impact does removing a Fragment in Android have on the performance of an application. What I am referring to is something like:

fragmentTransaction.remove(myFragment);

I've read the documentation about the Fragment Lifecycle Fragments and the description of the remove method in the Fragment Transaction Fragment Transaction remove() but haven't found whether calling the remove actually frees the memory occupied the Fragment's views.

Also, is there a way that I can suspend Fragments into a low memory state? The idea is that in an application with many Fragments and assuming that only one Fragment is visible at a time, is there anything I can do to optimize memory?

Your app should be optimized for best performance from design. It should not change it's behavior upon system resources. If you are low on memory, the background apps are killed so that your app can run smoothly and you user can get the best of it.

Just use a fragment when you need it. And remove it when it's not needed. If you do it the right way, you're already optimizing your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM