Why is there no autorelease pool when I do performSelectorInBackground:?

只愿长相守 提交于 2019-11-30 07:33:22

Most likely the reason for this is because the leaked object (an NSNumber), is a parameter passed in from outside the thread. Hence, this variable belongs to the calling thread (and its autorelease pool)

The reason that the autorelease pool around the thread call doesn't work, is because the thread creator (performSelectorInbackground) - returns immediately, most likely while the thread is still running.

I suggest you do a release on your selector's parameter after passing it in as an argument.

I agree that most likely the reason for this is because the leaked object (an NSNumber), is a parameter passed in from outside the thread. Hence, this variable belongs to the calling thread (and its autorelease pool)

The calling thread should use NSAutoreleasePool and I suggest that you add a retain instruction to your parameter as:

- (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj {
    NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
    [indexNumberObj retain];

    ....

    [arPool release];
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!