天天看點

asynchronous requests with NSURLConnection: when to release

up vote

down vote

favorite

share [fb]

share [tw]

Yet, when I do the same, I later get this in zombi-mode

*** -[NSURLConnection releaseDelegate]: message sent to deallocated instance 0x1001045b0

It seems, there's some code in AppKit which releases connection for me.

I'd be happy to assume that Apple guide is wrong, but do not want to get some terrible memory leak or introduce some subtle incompatibility with older OSX versions or something like that.

Is it safe to ignore documentation in this case?

edit

Code creating request

  URLConnectionDelegate *delegate = [[URLConnectionDelegate alloc] initWithSuccessHandler:^(NSData *response) {

      ...

  }];

  [NSURLConnection connectionWithRequest:request delegate:delegate];  

 // I do not release delegate when testing for this issue, not sure whether I should in general

Delegate class itself

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

  successHandler(receivedData);

  [receivedData release];

  Block_release(successHandler);

 // do we really need this????????

  [connection release];

}

asked Feb 6 at 1:24

<a href="http://stackoverflow.com/users/330565/nikita-rybak"></a>

<a href="http://stackoverflow.com/users/330565/nikita-rybak">Nikita Rybak</a>

24.7k32762

78% accept rate

show 4 more comments

Was this post useful to you?     

歡迎加群互相學習,共同進步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,轉載請注明出處!

本文轉自張昺華-sky部落格園部落格,原文連結:http://www.cnblogs.com/sunshine-anycall/archive/2011/12/05/2277119.html,如需轉載請自行聯系原作者

繼續閱讀