问题描述
我正在非 ARC 应用程序中的应用程序中动态更改窗口的 rootViewController.
I am changing rootViewController of window dynamically in my application in Non - ARC application.
我的问题是我需要释放之前分配的 rootViewController 吗?之前分配的 rootViewController 是如何管理内存的?
My question is do i need to release previously assigned rootViewController? How memory is management is done with previously allocated rootViewController?
我的第二个问题是关于 newrootViewController.我如何为窗口的新 rootViewController 管理内存.
My Second question is about newrootViewController. how i can manage memory for new rootViewController for window.
任何帮助将不胜感激....
Any help will be appreciated....
推荐答案
Jason 在上面的评论中是正确的,实际上很少有理由不使用 ARC.自动引用计数与手动引用计数一样有效.
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.
记住这不是垃圾回收,retain 和 release 语句只是在编译时添加的.
Remember it's not garbage collection, the retain and release statements are simply added at compile time.
回答你的问题,如果你在 rootViewController 上调用了 alloc
/new
或 copy
那么是你必须释放之前分配的控制器.
To answer your question, if you called alloc
/ new
or copy
on the rootViewController then yes you must release the previously allocated controller.
请记住,成为内存管理势利小人并不是不使用 ARC 的充分理由!;)
Remember being a memory management snob is not a sufficient reason to not use ARC! ;)
关于 newRootViewController 对象,只要你把它设置为 windows 的根视图控制器",窗口就会保留它,所以你可以释放它.
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.
也看看这个问题:保留 rootViewController?
这篇关于更改窗口的 rootViewController 的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!