1

我收到了崩溃日志:

2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbdef0 of class NSURL autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x1462e38 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x1462e38 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.233 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb32b0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fc04e0 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5f98960 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.235 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa9c70 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbfbb0 of class NSHTTPURLResponse autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb5840 of class __NSCFData autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.550 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb1400 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5f83e70 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fbd480 of class NSCFString autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb31b0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa9aa0 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.551 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fa6110 of class __NSArrayI autoreleased with no pool in place - just leaking
2011-07-21 23:18:51.552 iFeel[87679:910b] *** __NSAutoreleaseNoPool(): Object 0x5fb9700 of class NSCFString autoreleased with no pool in place - just leaking

任何机构都可以帮助我避免崩溃吗?

4

3 回答 3

3

您很可能会看到这种情况,因为您在没有自动释放池的线程上执行代码。Apple 的所有 API 都大量使用自动释放池,因此在整个线程中封装一个非常重要。这方面的一个例子如下:

- (void)myThreadMethod:(id)anObject {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"This is some objective-c code...");
    [pool drain];
}

[池排水]部分非常重要。如果没有那段代码,在线程生命周期内自动释放的所有对象都将被泄露。

于 2011-07-21T18:29:50.817 回答
1

设置NSAutoreleasePool. 查看NSAutoreleasePool 类参考以获取详细信息和示例。

您可能还想浏览一下内存管理编程指南,了解为什么设置它很重要以及autorelease实际做了什么。

我还发现这篇文章的讨论很有帮助:NSAutoreleasePool 自动释放池是如何工作的?

于 2011-07-21T18:24:07.593 回答
1

从 Apple 文档链接

NSAutoreleasePool 类用于支持 Cocoa 的引用计数内存管理系统。自动释放池存储在池本身耗尽时发送释放消息的对象。

重要提示:如果您使用自动引用计数 (ARC),则不能直接使用自动释放池。相反,您使用 @autoreleasepool 块。例如,代替:

 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
// Code benefitting from a local autorelease pool. 
[pool release];

你会写:

 @autoreleasepool {
     // Code benefitting from a local autorelease pool. 
}

@autoreleasepool 块比直接使用 NSAutoreleasePool 的实例更有效;即使您不使用 ARC,也可以使用它们。

于 2014-08-07T16:03:07.037 回答