Using ASIHTTP, the code below is in the ImageDownloader class. I get a memory leak, which is added at the bottom, but I don't know why. I thought tempImage would be autoreleased without me doing anything?
- (void)requestFinished:(ASIHTTPRequest *)request
{
UIImage *tempImage = [UIImage imageWithData:[request responseData]];
if (tempImage.size.width > 250.0f && tempImage.size.height > 180.0f)
{
self.image = tempImage;
self.circleImage = [UIImage imageNamed:@"hover.png"];
if ([self.delegate respondsToSelector:@selector(addImageToModel:)])
[self.delegate addImageToModel:self];
}
else
{
if ([self.delegate respondsToSelector:@selector(badImage)])
[s开发者_StackOverflowelf.delegate badImage];
}
tempImage = nil;
}
self.image is getting set to tempImage, so it probably retains the image. Is it released anywhere?
You should not write this line :
tempImage = nil;
Since tempImage is a function scope variable, it will be taking care of by itself. Further more, if self.image is (nonatomic, assign) that could be the origine of your leak.
About the stack trace image, is this from leak instruments, or memory instruments ?
Unfortunately, until you give away some more code, we won't be able to help you further.
As Thomas mentioned, it may be self.image retaining the image?
Have you considered waking up the zombies ? ;)
http://www.mikeash.com/pyblog/friday-qa-2011-05-20-the-inner-life-of-zombies.html
http://www.cocoadev.com/index.pl?NSZombieEnabled
精彩评论