Memory management with changing rootViewController of window

空扰寡人 提交于 2019-12-24 22:35:24

问题


I am changing rootViewController of window dynamically in my application in Non - ARC application.

My question is do i need to release previously assigned rootViewController? How memory is management is done with previously allocated rootViewController?

My Second question is about newrootViewController. how i can manage memory for new rootViewController for window.

Any help will be appreciated....


回答1:


Jason is right in his comment above, in reality there are very few reasons not to use ARC. Automatic reference counting is just as efficient if not more so than manual reference counting.

Remember it's not garbage collection, the retain and release statements are simply added at compile time.

To answer your question, if you called alloc / new or copy on the rootViewController then yes you must release the previously allocated controller.

Remember being a memory management snob is not a sufficient reason to not use ARC! ;)

With regard to the newRootViewController object, as soon as you make it the windows 'root view controller' the window retains it, so you can then release it.

Take a look at this question also: Retaining rootViewController?



来源:https://stackoverflow.com/questions/23101595/memory-management-with-changing-rootviewcontroller-of-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!