我意识到如果从应用程序中相应地删除子视图,内存管理似乎更好(我的应用程序中有很多子视图)。
所以我的问题是必须删除你创建的所有子视图或它的可选(当你的子视图很少,所以它不会影响内存使用量)?
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.
更多推荐
发布评论