On Dec 18, 2008, at 10:57 AM, Jonathan del Strother wrote:

Heya,
I ran into a memory leak recently that I finally managed to track down
to NSURLConnection retaining its delegate.

It appears that cancelling an NSURLConnection won't actually release
its delegate until the next time around the run loop.  Normally this
is fine, but I was running on a separate thread with its own run loop,
and I was just cancelling the connection & immediately exiting the
thread.

Is this a bug, undocumented feature, or am I missing something?


Risking yet another foot-in-mouth syndrome, I will comment.

I would file a radar both on NSURLConnection and the documentation. An object shouldn't be retaining its delegate except with good reason, and that reason (or simply the fact of the retention) should be well documented. Otherwise you could get a nasty retain cycle.

Anyway, it looks like NSURLConnection is releasing the delegate using a performSelector:withObject:afterDelay: or similar method. Running the run loop as you remark in the code is the only way I know of to make sure the delegate is released before the thread exits.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to