简体   繁体   中英

NSAutoreleasepool leaking - Don't understand why?

I have this code:

NSNumber *num;
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];

for (int i=0; i<images_count; i++) {
    num = [NSNumber numberWithInt:images_count];
    [self performSelectorInBackground:@selector(loadData:) withObject:num];
}

[apool release];
[num release];

and it generates the following error:

2011-06-17 03:10:30.768 CHARLIE[2456:6c03] * __NSAutoreleaseNoPool(): Object 0x703d0f0 of class __NSArrayI autoreleased with no pool in place - just leaking

I don't understand why its leaking, can someone please explain how to fix this?

Thanks a lot,

Jack

There are a couple of issues with that code.

  • The lack of an autorelease pool is probably due to the loadData: method running without an autorelease pool.

  • The [num release] is nonsense.

  • Spawning a thread per every iteration of that loop is pretty much guaranteed to be the least performant possible approach to parallelizing image loading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM