我知道這一定是簡單的東西,我俯瞰,但爲什麼這泄漏:NSAutoreleasePool泄漏
//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():對象0x4e2fdf0類NSPathStore2自動釋放與沒有到位的地方 - 只是漏水
我試着移動[pool drain]的位置,但是什麼也沒做。在Google搜索某個原因時,我看到很多代碼看起來就像這樣。
感謝您的幫助。
您正在泄漏`myImageView`(它需要被釋放)。除此之外,乍一看,一切都很好。 – kubi 2011-01-19 15:44:38