开发者

NSURLConnection

So why is it that you instantiate a NSURLConnection and then release it on the next line? I know that it involves the use of delegate, bu开发者_JAVA百科t I'm a little confused.


You should not release a NSURLConnection after instatiate it. Unless, off course, if you are using it as a retain property (as correctly pointed by @ArtGillespie)

When you instantiate it, the retain count will be only 1, and if you release it, the retain count will be set to 0, then the object will be cleaned from memory and you might be pointing to an invalid position in memory from that moment on.

If you have it as a retain property, you will be adding 1 to the retain count when assigning the property value. So your retain count will be 2 after instantiating and assigning. Then the right thing to do is release it so that the retain count goes back to 1, and you can properly release the object after the connection has finished (or set the property to nil, which will cause the object to be released as well)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜