我知道这一定是我忽略了的一些简单的东西,但是为什么它会泄露:
//add a pool for this since it is on its own thread
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//add the image
NSURL * imageURL = [NSURL URLWithString:[recipeData objectForKey:@"imagePath"]];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
UIImageView * myImageView = [[UIImageView alloc] initWithImage:image];
//resize to make it fit the screen space
CGRect frame = myImageView.frame;
frame.size.width = 320;
frame.size.height = 357;
myImageView.frame = frame;
[self.view addSubview:myImageView];
[activity stopAnimating];
[pool drain];
[self placeItems];我得到了错误:
_NSAutoreleaseNoPool():NSPathStore2类的对象0x4e2fdf0在没有池的情况下自动释放-只是泄漏
我试着移动水池排水口的位置,但什么也没做。当我在谷歌上搜索一个原因时,我看到了很多看起来像这样的代码。
谢谢你的帮助。
发布于 2011-01-19 23:56:24
排出池具有释放并随后释放它的效果,因为自动释放池不能被保留。我怀疑在placeItems (或其他以[pool drain]命名的地方)中一定需要一个自动释放池,因为在这一点上,池可能已经消失了。
因此,您可能希望尝试注释掉排出消息,看看这是否会使泄漏消失。
发布于 2011-01-20 00:05:49
这里有很多要说的:
myImageView。你必须在主线程之后释放它,因为你在另一个线程上,你的池排出必须在[self.view performSelectorOnMainThread:@selector(addSubview:) withObject:myImageView waitUntilDone:YES]替换[self.view addSubview:myImageView]。与[activity stopAnimating].相同
就像Brian说的,-drain消息必须在你的线程的末尾。
https://stackoverflow.com/questions/4737262
复制相似问题