Hello. I have a class that's very similar to MultipleDownload.m by leonho. Basically, in a pretty tight loop, I spawn a bunch of NSURLConnections and keep track of received data using a method similar to that used in MultipleDownload.m. There are changes in my code that was necessitated by needing to save files to the camera roll in the same order as was requested, but those changes shouldn't have anything to do with the problems I've run into.
Here's that loop that spawns the NSURLConnections (this is a straight copy from MultipleDownload.m):
for(NSInteger i=0; i< [urls count]; i++){
NSMutableData *aData = [[NSMutableData alloc] init];
[receivedDatas addObject: aData];
[aData release];
NSURLRequest *request = [[NSURLRequest alloc]
initWithURL: [NSURL URLWithString: [urls objectAtIndex:i]]
cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval: 10];
NSURLConnection *connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:self];
[requests setObject: [NSNumber numberWithInt: i]
forKey: [NSValue valueWithNonretainedObject:connection]];
[connection release];
[request release];
}
When I spawn smallish number of NSURLConnections, my code works fine -- all the files are downloaded and saved (in order!). But when I spawn 200+ files, I'm finding that only a hundred or so start downloading. In the NSURLConnection delegate methods (namely - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
and - (void)connectionDidFinishLoading:(NSURLConnection *)connection
), I put NSLog messages and found that my collection of remaining NSURLConnections just don't do anything.
Any ideas on why this might be happening? Am I just running out of memory and those NSURLConnections are getting chucked?
Thanks!