Skip navigation.
 
mlNSURLConnection retains its delegate
FROM : Jonathan del Strother
DATE : Thu Aug 10 18:30:13 2006

I ran into an odd problem recently where my objects that I created to 
receive a response from an NSURLConnection were never getting 
released.  After several hours of debugging, I finally discovered 
that NSURLConnection seems to retain its delegate.


BBConnectionHandler* connectionHandler = [[BBConnectionHandler alloc] 
init];    //connectionHandler has a retain count of 1
NSURLConnection* connection = [NSURLConnection 
connectionWithRequest:request delegate:connectionHandler];
//connectionHandler now has a retain count of 2.

...which all lead to a rather unpleasant retain cycle that was a pain 
in the ass to unwind.


Surely this is wrong?  I'm sure I remember reading somewhere that 
objects should not retain their delegates for exactly the above 
reason.  This isn't standard behavior - shouldn't it at least be 
documented?


Jon

Related mailsAuthorDate
mlNSURLConnection retains its delegate Jonathan del Strot… Aug 10, 18:30
mlRe: NSURLConnection retains its delegate Scott Anguish Aug 11, 00:53
mlRe: NSURLConnection retains its delegate Jerry Krinock Aug 11, 06:58
mlRe: NSURLConnection retains its delegate Scott Anguish Aug 11, 10:05