首页 > NSURLConnection为什么在请求结束之前不会被释放

NSURLConnection为什么在请求结束之前不会被释放

如题,

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.sqlite.org/2016/sqlite-amalgamation-3120100.zip"]] delegate:self];
[conn start];

假设这种情况下,我用NSURLConnection请求一个比较啊的文件,为什么在这种情况下,在请求结束之前NSURLConnection不会被释放呢?此时没有任何对象强引用它


看看 start 的文档,call conn 的 start 方法时,会把这个 conn 加到一个 run loop 里去,这就是为什么它没被释放, run loop “引用”了它。

Causes the connection to begin loading data, if it has not already.
Calling this method is necessary only if you create a connection with the initWithRequest:delegate:startImmediately: method and provide false for the startImmediately parameter. If you don’t schedule the connection in a run loop or an operation queue before calling this method, the connection is scheduled in the current run loop in the default mode.
【热门文章】
【热门文章】