When is an auto-commercial released?

I am developing an iPhone, objective-c. When we use autorelease, when the object is really freed - when the main pool of auto resources is freed (that is, the application terminates?) Or as soon as the local function ends? For example, I want to do something like this:

- (void) test
{
    MyObj * p = [[[[MyObj alloc] init] autorelease];
    ...

    // is p 'released' here?
}

So, "p" is issued as soon as the function exits, or when the autostart pool of this thread is freed? I thought this happens when the local function exits, but I just created my own thread and had to set up an autostart pool, which gives me a second thought about when this actually happens.

thanks

+5
source share
2 answers

The autoreleases object will be released at the same time as the autoplay pool. Thus, for your thread, it will be released when the pool is released. In the main thread, if you do not create your own, I believe that the auto-resource pool merges every time through the launch cycle, but I did not look at that time.

+6
source

As Argotian says, it is freed up when the auto-calculation pool is released, which happens every time through the launch cycle in a regular Cocoa application, and not when the application terminates (unless, of course, you have a startup cycle, in this case you need to create an auto-resource pool and release it independently). Autodetection pools are not aware of every single function call and therefore cannot release things at the end of a function call.

+1

All Articles