I have an object that encapsulates an asynchronous NSURL request. When should I release it?
StrangersRequest *request = [[StrangersRequest alloc] init];
request.strangersListener = strangersListener;
[request send];
Analyze in XCode says I should release it immediately – but that’s not right because it has to handle the URLRequest callback.
What’s an appropriate pattern for releasing objects that handle asynchronous events?
I’m guessing I should release when the request completes (connectionDidFinishLoading). If so, how can I stop Analyze from complaining about it?
You could follow the
NSThreadmodel and have the object retain itself until its asynchronous task has completed.