Search code examples
iphoneobjective-ciosxcodesubviews

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)?


Solution

  • 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.