Any idea on how to release the UIImage object picture in this case:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *payload = [[UIImage alloc] initWithData:self.activeDownload];
UIImage *picture = [[UIImage alloc] init];
if (payload.size.width != kAppIconHeight && payload.size.height != kAppIconHeight)
{
CGSize itemSize = CGSizeMake(kAppIconHeight, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[payload drawInRect:imageRect];
picture = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
picture = payload;
}
self.activeDownload = nil;
[payload release];
self.imageConnection = nil;
[delegate ThumbDidLoad:self.indexPathInTableView Image:picture];
}
Thx for helping,
Stephane
I’m having a hard time understanding why your “picture” variable has an alloc init at all. I agree with earlier answers to use autorelease, but perhaps something more like:
Couple changes above:
1.
UIImage *payload = [UIImage imageWithData:self.activeDownload];. Changed this assignment to an autoreleased object since picture may be assigned to it. Note that theifclause assignspictureto an autoreleased object, so theelseclause should too and now it does since payload is now an autoreleased object.2.
UIImage *picture = nil;instead ofUIImage *picture = [[UIImage alloc] init];. I did this since the picture assignment is NEVER used, so nil is actually valid since it will definitely be assigned in either theiforelseclause.3. No need for
[payload release]now thatpayloadis autoreleased.