Iphone 多线程和“刚刚泄漏”警告
我正在创建一个新线程,如下所示:Iphone 多线程和“刚刚泄漏”警告,iphone,objective-c,cocoa-touch,multithreading,Iphone,Objective C,Cocoa Touch,Multithreading,我正在创建一个新线程,如下所示: [NSThread detachNewThreadSelector: @selector(myMethod:) toTarget:self withObject:filePath]; 我的方法是: - (void) myMethod:(NSString*)path{ NSAutoreleasePool *pool = [NSAutoreleasePool alloc]; [UIImagePNGRepresentation(theImage) writeToF
[NSThread detachNewThreadSelector: @selector(myMethod:)
toTarget:self withObject:filePath];
我的方法是:
- (void) myMethod:(NSString*)path{
NSAutoreleasePool *pool = [NSAutoreleasePool alloc];
[UIImagePNGRepresentation(theImage) writeToFile:[path stringByAppendingString:@".png"] atomically:NO];
[pool release];
}
但是不断地得到这些警告:
*** _NSAutoreleaseNoPool(): Object 0x194b1c0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
Stack: (0x305a2e6f 0x30504682 0x309084ff 0x3a0d 0x3050a79d 0x3050a338 0x9100cfbd 0x9100ce42)
*** _NSAutoreleaseNoPool(): Object 0x19014c0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x305a2e6f 0x30504682 0x3a30 0x3050a79d 0x3050a338 0x9100cfbd 0x9100ce42)
在被调用的方法中创建一个NSAutoreleaseNoPool对象,然后以使用线程@selector的正确方式释放它,不是吗?您没有完全初始化自动释放池:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
您没有完全初始化自动释放池:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
请尝试以下代码:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do stuff
[pool drain];
希望这有帮助尝试以下代码:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do stuff
[pool drain];
希望这有帮助