7. Name does matter
• begin with alloc/new/copy/mutableCopy will not be put
into autorelease pool
• others will add object into autorelease pool automatically
-(id) newCar;
13年5月27⽇日星期⼀一
13. Clean pool nicely
int i;
for (i = 0; i < 1000000; i++) {
id object = [someArray objectAtIndex: i];
NSString *desc = [object description];
// and do something with the description
}
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
int i;
for (i = 0; i < 1000000; i++) {
id object = [someArray objectAtIndex: i];
NSString *desc = [object description];
// and do something with the description
if (i % 1000 == 0) {
[pool drain];
pool = [[NSAutoreleasePool alloc] init];
}
}
[pool release]
iOS 4
13年5月27⽇日星期⼀一
14. Clean pool nicely
int i;
for (i = 0; i < 1000000; i++) {
id object = [someArray objectAtIndex: i];
NSString *desc = [object description];
// and do something with the description
}
int i;
for (i = 0; i < 1000000; i++) {
@autoreleasepool{
id object = [someArray objectAtIndex: i];
NSString *desc = [object description];
// and do something with the description
}
}
iOS 5
13年5月27⽇日星期⼀一