NSAutoReleasePool 泄漏
谁能告诉我为什么 NSAutoreleasePool 在这段代码中泄漏。我正在使用仪器来检查泄漏和泄漏。这段代码不知何故泄漏了。谁能引导我走向正确的方向。我在其他地方有完全相同的代码&它运行良好。
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:self.url];
[request setDelegate:self];
NSOperationQueue *queue = self.downloadQueue;
[queue addOperation:request];
[request release];
Can anyone tell me why is NSAutoreleasePool leaking in this code. I am using instruments to check leaks & this code is somehow leaking. Can anyone guide me to the right direction. I have the exact same code elsewhere & its running fine.
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:self.url];
[request setDelegate:self];
NSOperationQueue *queue = self.downloadQueue;
[queue addOperation:request];
[request release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您围绕该代码创建 NSAutoreleasePool,它应该会消失。如果此代码未在主线程上运行,通常会发生这种情况。
另外,请注意,如果您在 NSAutoreleasePool new/drain 块内循环,则会出现泄漏,直到到达排水管。这样做的结果是,如果您在循环内分配太多内存,您的应用程序仍然可能会耗尽内存。在这种情况下,您可能需要在每次循环中创建并耗尽第二个 NSAutoreleasePool (或者可能每第 n 次循环以避免一些开销)。
It should go away if you create an NSAutoreleasePool around that code. This usually happens if this code is not being run on the main thread.
Also, be aware that if you are looping inside an NSAutoreleasePool new/drain block, you will appear to leak until you hit the drain. The upshot of this is if you are allocating too much memory inside the loop your app can still run out of memory. In that case you may need to create and drain a second NSAutoreleasePool every time through the loop (or possibly every nth time through the loop to avoid some of the overhead).
您是否在辅助线程上运行此代码?如果是这样,您是否在入口处设置了自动释放池?
Are you running this code on a secondary thread? If so did you setup an autorelease pool on entry?