问题描述
我很难准确理解何时在 AppKit 应用程序中创建和发布自动释放池.
I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps.
例如,如果我有一个覆盖 init 的 ApplicationController 类,是否有一个自动释放池在它开始之前被创建并在它结束后被耗尽?
For example, if I have an ApplicationController class that overrides init, is there an autorelease pool that gets created before it starts and gets drained after it ends?
推荐答案
AppKit 应用程序中的主线程运行 NSRunLoop 来处理事件.NSRunLoop 每次处理新事件(或计时器)时都会创建一个新的自动释放池,并在控制流返回到 NSRunLoop 时将其排空.所以本质上,每次通过运行循环都有一个新的自动释放池.
The main thread in an AppKit application runs an NSRunLoop to process events. NSRunLoop creates a new autorelease pool every time it processes a new event (or timer) and drains it once control flow has returned to the NSRunLoop. So in essence, every pass through the run loop has a fresh autorelease pool.
这篇关于appkit 应用程序中的自动释放池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!