本文介绍了在appkit应用程序中自动释放池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法正确了解何时在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应用程序中自动释放池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:51