开发者

how to avoid memory leaking when calling function in backgroundThread

I have problem with memory leak when i call function in background thread like

[self performSelectorInBackground:@selector(myFunctionName) withObject:nil];

when this function is called in background the following warning displayed:

2009-12-26 16:05:46.777 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x63851d0 of class NSURL autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x305440c1 0x8ca69 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.800 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0xe81090 of class NSURLRequest autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x8ca9b 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.816 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x63cc720 of class NSCFString autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x305fed64 0x3058ae69 0x8cadb 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.819 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0xe0b480 of class NSCFString autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x30603183 0x305fed80 0x3058ae69 0x8cadb 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.840 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x63a2dc0 of class NSCFString autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x305fedb6 0x3058ae69 0x8cadb 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.846 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x64060b0 of class NSCFString autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x30560183 0x305fedd2 0x3058ae69 0x8cadb 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.880 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x63b25c0 of class NSThread autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x30509c04 0x3055fe8e 0x923b589e 0x30560f25 0x30570c41 0x30570ae3 0x30570a67 0x923b589e 0x30570a15 0x305fee2c 0x3058ae69 0x8cadb 0x8cbe0 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)
2009-12-26 16:05:46.911 SimpleGame[11450:99fb] *** _NSAutoreleaseNoPool(): Object 0x6329660 of class NSCFArray autoreleased with no pool in place - just leaking Stack: (0x305a2e6f 0x30504682 0x3055fee0 0x923b589e 0x30560f25 0x30570c41 0x30570ae3 0x30570a67 0x923b589e 0x30570a15 0x305fee2c 0x3058ae69 0x8cadb 0x8cbe0开发者_StackOverflow 0x3050a79d 0x3050a338 0x923c4155 0x923c4012)

I have no idea what to do.so plz someone help me.


Each thread should have NSAutoreleaseNoPool created for it.


Girish is right, each thread needs it's own autorelease pool. Here is an example:

- (void)myBackgroundMethod
{
  NSAutoreleasePool*pool=[[NSAutoreleasePool alloc] init];

  /* Code Body */

  [pool release];
  return;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜