为什么删除子视图?(Why remove subview?)

编程入门 行业动态 更新时间:2024-10-27 18:18:08
为什么删除子视图?(Why remove subview?)

我意识到如果从应用程序中相应地删除子视图,内存管理似乎更好(我的应用程序中有很多子视图)。

所以我的问题是必须删除你创建的所有子视图或它的可选(当你的子视图很少,所以它不会影响内存使用量)?

I realise if I remove subviews accordingly from my application, the memory management seems better ( I have a lot of subviews inside my application).

So my question is it is a must to remove all subviews that you have created or its optional (when you have very little subviews so it doesn't affect the memory usage much)?

最满意答案

您看到接口响应明显跳跃,因为子视图实际上消耗了相当多的内存(UIViews与其底层CALayers相比非常昂贵),因此,调用-removeSubview不仅可以卸载来自GPU的压力,还可以释放由于子视图通常会在之后发布,因此可以获得更多内存。

但是要回答你的问题:不会。一旦视图超出了上下文,或从子视图树中删除,它自己的子视图树就会被破坏,视图会在ARC环境中释放,然后为你销毁。 即使没有ARC,也没有必要。

You are seeing a noticeable jump in interface response because subviews do in fact consume quite a bit of memory (UIViews are very expensive compared to their underlying CALayers), and as such, calling -removeSubview not only unloads stress from the GPU, but also frees up more memory as the subview is usually released afterwards.

But to answer your question: No. Once a view has passed out of context, or removed from the subview tree, it's own subview tree is broken, the views are released in an ARC environment, then destroyed for you. Even without ARC, it's unnecessary.

更多推荐

本文发布于:2023-04-27 22:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   remove   subview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!