I have a view which has a UITableView where I am lazy loading images. I have a class called ThumbDownloader where I initialize an NSURLConnection and upon finishing loading the image when connectionDidFinishLoading is called, within connectionDidFinishLoading, I make a call like this back to my main view:
[delegate appImageDidLoad:self.indexPathInTableView];
In my main view I have an array of ThumbDownloader instances. The array is named: imageDownloadsInProgress
The problem is, if I enter the view and quickly exit it before all of the images are done downloading, I get the zombie:
-[myApp appImageDidLoad:]: message sent to deallocated instance 0xa499030
I have tried a bunch of ways to release the ThumbDownloader instances in dealloc and such, but nothing seems to work.
Here is where I set up the instance and add it to the array:
- (void)startIconDownload:(Product *)product forIndexPath:(NSIndexPath *)indexPath
{
ThumbDownloader *thumbDownloader = [imageDownloadsInProgress objectForKey:indexPath];
if (thumbDownloader == nil)
{
thumbDownloader = [[ThumbDownloader alloc] init];
thumbDownloader.product = product;
thumbDownloader.imageSizeWidth = 87;
thumbDownloader.imageSizeHeight = 87;
thumbDownloader.indexPathInTableView = indexPath;
thumbDownloader.delegate = self;
[imageDownloadsInProgress setObject:thumbDownloader forKey:indexPath];
[thumbDownloader startDownload];
[thumbDownloader release];
}
}
Make sure you clear the delegate on the NSURLConnection.