asynchronous requests with NSURLConnection: when to release

简介:

up vote

0

down vote

favorite


share [fb]

share [tw]

Apple guide is very specific about releasing connection object: it's done in didFailWithError and connectionDidFinishLoading.

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];

}

objective-c cocoa nsurlconnection

link|edit

edited Feb 6 at 2:51



asked Feb 6 at 1:24


Nikita Rybak

24.7k32762


78% accept rate



From the docs: ‘NSURLConnection retains its delegate when it is initialized. It releases the delegate when the connection finishes loading, fails, or is canceled.’ It looks like you have over-released the delegate. – Bavarious Feb 6 at 2:29


@Bavarious I don't release delegate here. (whether I should is another question) Error appears when I add [connection release]; and goes away when I remove it. – Nikita Rybak Feb 6 at 2:32


@Bavarious Also, error wording suggests that method releaseDelegate was invoked on released NSURLConnection instance. Not on delegate. – Nikita Rybak Feb 6 at 2:33


Which object is the URL connection delegate? What is its lifecycle? – Bavarious Feb 6 at 2:36


Hmm, maybe. I’m not familiar with zombies. Would you be willing to paste the code that creates the connection and handles its delegate methods? – Bavarious Feb 6 at 2:39

show 4 more comments

Was this post useful to you?     

欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!
相关文章
|
2月前
|
网络安全 数据安全/隐私保护
requests.exceptions.SSLError: HTTPSConnectionPool问题
这篇文章介绍了解决`requests.exceptions.SSLError: HTTPSConnectionPool`错误的几种方法,包括关闭SSL证书验证、安装相关的加密库以及禁用urllib3的警告。
|
2月前
|
JavaScript 前端开发
NodeJs——error:03000086:digital envelope routines::initialization error
NodeJs——error:03000086:digital envelope routines::initialization error
47 0
|
5月前
|
前端开发 JavaScript
Asynchronous, async
Asynchronous(异步)和async(async函数)是JavaScript中用于处理异步操作的关键概念。
43 7
|
5月前
nodejs17/18版本报错:digital envelope routines::unsupported
nodejs17/18版本报错:digital envelope routines::unsupported
162 0
|
关系型数据库 PostgreSQL Ruby
HTTP 502: Whoops, GitLab is taking too much time to respond.
最近有台云上的服务器需要释放,然后上面跑的 gitlab 也要挪个地方,如在 docker 内运行,gitlab 镜像大约 1.56G,需占用 4G 以上的内存,因资源有限,于是借在其他的服务器上搭建环境(可用内存小于4G),然鹅启动的时候莫名出现 502,Excuse me?接着搜了一些 issue 博客上的解决方案(如修改端口、重启或 hup 某个服务)无果,后来在调整的过程中从日志里发现了一些信息。
11993 0
|
12月前
|
应用服务中间件 开发工具 nginx
【git】解决:error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413
【git】解决:error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413
400 0
|
开发工具 git
git 报错 RPC failed; curl 18 transfer closed with outstanding read data remaining
这个错误是因为项目太久,tag资源文件太大 找了很久网上都说这样: 配置如下: $ git  config --global http.
9276 0
|
Dart 开发工具 Android开发
【错误记录】Flutter 报错 Downloading the Dart SDK using the BITS service failed, retrying with WebRequest...
【错误记录】Flutter 报错 Downloading the Dart SDK using the BITS service failed, retrying with WebRequest...
524 0
【错误记录】Flutter 报错 Downloading the Dart SDK using the BITS service failed, retrying with WebRequest...
SpringCloud - feign.RetryableException: Read timed out executing POST
SpringCloud - feign.RetryableException: Read timed out executing POST
1577 0