Fragment 保留的内存

发布于 2024-12-09 18:01:48 字数 503 浏览 2 评论 0原文

当我像这样调用 popBackStack 时:

manager.popBackStack("mybackstack", FragmentManager.POP_BACK_STACK_INCLUSIVE);

属于“mybackstack”的片段保留的内存将被释放吗?

我有一个管理 ListFragmentFragmentActivity 。每次我单击项目时,FragmentActivity 都会实例化一个新的 Fragment,其中显示有关单击的项目的一些信息,然后显示带有位图的 DialogFragment (当对话框关闭时我会回收)。我将 android:configChanges="orientation" 放入清单中,并根据需要重写 onConfigurationChanged

When I call the popBackStack like:

manager.popBackStack("mybackstack", FragmentManager.POP_BACK_STACK_INCLUSIVE);

will the memory retained by the fragments that belongs to "mybackstack" will be freed?

I have a FragmentActivity that manages a ListFragment. Every time I click on item, the FragmentActivity instantiates a new Fragment which shows some information about the item clicked and then shows a DialogFragment with a Bitmap (that I recycle when the dialog is dismissed). I put the android:configChanges="orientation" in the manifest and override onConfigurationChanged as necessary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百合的盛世恋 2024-12-16 18:01:48

是的,片段保留的内存将被释放。从文档来看,

公共静态最终 int POP_BACK_STACK_INCLUSIVE

popBackStack(String, int) 和 popBackStack(int, int) 的标志:
如果设置,则返回堆栈的名称或 ID
条目已被提供,那么所有匹配的条目将被消耗
直到找到不匹配的一个或栈底
达到了。否则,直到但不包括该条目的所有条目
将被删除。

和,

公共抽象无效popBackStack(字符串名称,int标志)

从管理器的片段返回堆栈中弹出最后一个片段转换。
如果没有要弹出的内容,则返回 false。这个函数是
异步——它将请求放入队列以弹出,但操作将
在应用程序返回其事件循环之前不会执行。

但请注意,不能保证该内存会立即被释放。

Yes, the memory retained by the fragments will be freed. From the documentation,

public static final int POP_BACK_STACK_INCLUSIVE

Flag for popBackStack(String, int) and popBackStack(int, int):
If set, and the name or ID of a back stack
entry has been supplied, then all matching entries will be consumed
until one that doesn't match is found or the bottom of the stack is
reached. Otherwise, all entries up to but not including that entry
will be removed.

and,

public abstract void popBackStack (String name, int flags)

Pop the last fragment transition from the manager's fragment back stack.
If there is nothing to pop, false is returned. This function is
asynchronous -- it enqueues the request to pop, but the action will
not be performed until the application returns to its event loop.

Note, however, that there is no guarantee that this memory will be freed immediately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文