End of startup cycle - autoresist pool recovery

As I understand it, auto-implemented objects are cleared after releasing the auto-implemented pool. The auto resource pool will now be released at the end of the run loop.

My question is: if in my class I do not create a custom autostart pool and do not call the autodetection method on some objects of this class, at what point will these objects be restored? Is “end of cycle loop” meant “end of application”?

+6
source share
3 answers

You must understand the concept of a startup cycle. A run in iOS waits for an event to happen, and then it acts on it. This event can be a user touching the screen, receiving a call, etc.

For each such event that iOS processes, a new autostart pool is created at the beginning and is reset when event processing is complete. Theoretically, there could be any number of nested autorun pools created using Cocoa Touch, but the main one you should know is the event loop.

Perhaps this diagram from the application life cycle will help.

UIKit event loop .

In pseudo code, it comes down to

int UIApplicationMain(...) { while (!shouldQuitApplication) { Event *someEvent = // wait for next event; NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init]; // handle event [myPool release]; } } 

These are the types of events in iOS.

 UIEventTypeTouches, UIEventTypeMotion, UIEventTypeRemoteControl, 

So, after processing each touch, movement or remote control event, the pool will be drained.

+20
source

The “end” of the run loop means the end of each iteration of the run loop, not the end of the application.

+3
source

Not really. Imagine that RunLoop has "circles" :) At the beginning of each "circle" RunLoop creates an Autorelease pool and depletes it before leaving the "circle".

0
source

Source: https://habr.com/ru/post/886551/


All Articles