Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top