Objective-c: returning an object of an auto-implemented object from a method

What prevents the release of an autorealized instance NSArraybefore it is used in the method that it returns?

- (NSArray *) f {
    return [NSArray array];
}

- (void) g {
    NSArray *a = [self f];
    // do something with a
}
+3
source share
3 answers

What prevents the release of a self-implemented instance of NSArray before it is used in the method that it returns?

Autofill pools per thread . That is, an auto-implemented object is, in fact, a delayed call releasethat occurs on each thread.

, drain , - ( ).

, , :

• GCD , " " ( ). NSOperationQueue

• .

, , .

( , , retainCount : , autorelease, . , / , , , .)

+5

, . - , . , . , . , , .

+4

The autoresist pool merges during an iteration of the event loop. Since this is a leak that causes release messages to be sent to auto-implemented objects, they are still valid in the calling method.

+2
source

All Articles