2011-07-21 29 views
1

我得到的东西崩溃日志:如何避免在iPhone应用程序泄漏?

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 

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

回答

3

这是最有可能的,你是因为你在一个线程,但不自动释放池执行代码看到这个。自动释放池被所有苹果的API大量使用,所以重要的是在你的整个线程中包装一个。一个例子如下:

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

[pool drain]部分是非常重要的。如果没有这段代码,在线程生命周期中自动释放的所有对象都将被泄漏。

+1

我正在使用xcode 4.2与ARC。在该NSAutoreleasePool已弃用。我的应用程序没有崩溃,但在日志相同的日志即将到来。它对我的应用程序有害吗?请帮帮我。 – python

1

从苹果文档link

的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,也可以使用它们。