问题
I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps.
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?
回答1:
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.
来源:https://stackoverflow.com/questions/4047647/autorelease-pools-in-appkit-applications