I'm implementing asynchronous image loading in UITableView
, If I scroll rows fast my app crashes due to message sent to zombie... What is wrong am I doing here?
//loading image from URL
-(void)loadImageFromURL:(NSURL*)url {
if (connection!=nil) { [connection release]; }
//data is NSMutableData
if (data!=nil) { [data release]; }
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
//Append received data when it is received
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) { data = [[NSMutableData alloc] init]; }
[data appendData:incrementalData]; //Message sent to zombie, app CRASHES HERE
}
//When finished
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
//so self data now has the complete image
[connection release];
connection=nil;
//Use received data to construct image
[data release];
data=nil;
}