Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 多线程和“刚刚泄漏”警告_Iphone_Objective C_Cocoa Touch_Multithreading - Fatal编程技术网

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];
希望这有帮助