我正在获取事件崩溃日志:
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有没有人能帮我避免崩溃?
发布于 2011-07-22 02:29:51
很可能是因为您在没有自动释放池的线程上执行代码,所以才会看到这种情况。所有Apple的API都会大量使用自动释放池,所以在整个线程中使用一个自动释放池是很重要的。下面是一个这样的例子:
- (void)myThreadMethod:(id)anObject {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"This is some objective-c code...");
[pool drain];
}水池排水口部分非常重要。如果没有这段代码,在线程生命周期内自动释放的所有对象都将被泄漏。
发布于 2011-07-22 02:24:08
设置NSAutoreleasePool的实例。有关详细信息和示例,请查看NSAutoreleasePool Class Reference。
您可能还想浏览一下Memory Management Programming Guide,看看为什么设置它很重要,以及autorelease实际做了什么。
我还发现这篇文章的讨论很有帮助:How does the NSAutoreleasePool autorelease pool work?
发布于 2014-08-08 00:03:07
来自苹果文档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,您也可以使用它们。
https://stackoverflow.com/questions/6780788
复制相似问题