开发者

NSAutoreleasepool leaking - Don't understand why?

I have this code:

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

for (int i=开发者_StackOverflow中文版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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜