Handling Multiple NSURLConnections
Handling Multiple NSURLConnections
- Subject: Handling Multiple NSURLConnections
- From: emh <email@hidden>
- Date: Sat, 7 Feb 2004 14:24:10 -0800
I am writing an app which I would like to have the ability to handle
multiple concurrent downloads.
The memory management issues have me scratching my head a little bit...
as I am fairly new to cocoa, can someone (in)validate my line of
thought?
I plan on having a Controller object which may receive retrieve
messages. Each time retrieve is called it instantiates a ConnHandler
which does the work creating and being a delegate for a
NSURLConnection. when the download is finished the Controller is
notified so that the controller can get at the received data and
release the ConnHandler.
Here is some code (untested) -- is this the correct approach regarding
alloc/retain/release? Should I be using autorelease? should i be doing
something entirely different?
Controller:
- (void) retrieve {
ConnHandler* ch = [[ConnHandler alloc] initWithOwner: self];
// above line immediately returns as it is asynch
[ch retain];
}
ConnectionHandler:
- (id) initWithOwner:(Controller*)owner {
myOwner = owner;
myConnection = [[NSURLConnection alloc] initWithRequest: ... delegate:
self];
}
// assume methods to receive and parse incoming data into "results"
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[myConnection release];
[myOwner acceptResults: self];
}
Controller:
- (void) acceptResults:(ConnHandler*)handler {
results = [handler results];
// do something with results
[handler release];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.