运行循环结束——自动释放池恢复
据我了解,一旦自动释放池被释放,自动释放的对象就会被清理。现在,自动释放池将在运行循环结束时释放。
我的问题是,如果在我的类中我没有创建自定义自动释放池并对该类中的某些对象调用 autorelease 方法,那么这些对象在什么时候会被恢复? “运行循环结束”是否意味着“应用程序结束”?
As I understand, autoreleased objects are cleaned once an autoreleased pool is released. Now, autorelease pool will be released at the end of the run loop.
My question is, if in my class I am not creating a custom autorelease pool and calling the autorelease method on some objects in that class, at what point will those objects be recovered? Is the "end of the run loop" imply the "end of application"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须了解运行循环的概念。 iOS 中的运行循环等待某个事件发生,然后对其采取行动。该事件可能是用户触摸屏幕、接听电话等。
对于 iOS 处理的每个此类事件,都会在开始时创建一个新的自动释放池,并在事件处理完成时耗尽。理论上,Cocoa Touch 可以创建任意数量的嵌套自动释放池,但您应该了解的主要一个是事件循环。
也许这个图表来自应用程序生命周期 会有帮助。
。
在伪代码中,这可以归结为,
这些是 iOS 中的事件类型
,因此在处理每个触摸、运动或远程控制事件后,池将被清空。
You have to understand the concept of a run-loop. The run loop in iOS waits for some event to happen and then it acts upon it. That event could be the user touching the screen, receiving a call, etc.
For every such event that iOS handles, a new autorelease pool is created at the beginning and drained when the event processing is complete. Theoretically there could be any number of nested autorelease pools created by Cocoa Touch, but the main one you should know about is the event loop.
Maybe this diagram from the Application Life Cycle will help.
.
In pseudo-code, this boils down to,
These are the event types in iOS
So after every touch, motion, or remote control event is processed, the pool will be drained.
运行循环的“结束”意味着运行循环每次迭代的结束,而不是应用程序的结束。
The "end" of the run loop means the end of each iteration of the run loop, not the end of the application.
并不真地。想象一下 RunLoop 有“圈子”:) 在每个“圈子”的开始,RunLoop 创建自动释放池并在退出“圈子”之前耗尽它。
Not really. Imagine that RunLoop has "circles" :) In the begin of every "circle" RunLoop creates Autorelease pool and drains it before quitting the "circle".