Apple 代码中缺少发布版本?
在此 Apple 代码中: http://developer.apple.com/library /ios/#qa/qa1702/_index.html
我可以看到在init方法开始时分配的会话没有释放。
为什么 ?这是有原因的吗?
In this Apple code: http://developer.apple.com/library/ios/#qa/qa1702/_index.html
I can see that the session allocated at the start of the init method is not released.
Why ? Is there a reason to this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到了几个可能的原因:
autorelease
调用。init
方法末尾获取session
的 ivar 被声明为@property (assign)
,因此他们故意希望保留它目前。如果我没记错的话,这是一种糟糕的做法 - 他们应该有autorelease
d 会话并声明@property (retain)
。释放
会话
。严格来说,这并不是不好的做法,但肯定会令人困惑且难以阅读,并且可能会导致以后维护中的错误(当有人失去对retain
-release
平衡的跟踪时)。无论如何,你是对的,这与良好的内存管理实践有些不一致。然而,很难确定它是否有明确的原因没有发布。
A couple possible reasons come to mind:
autorelease
call later in the same snippet.session
at the end of theinit
method is declared@property (assign)
, and so they deliberately wanted to keep it retained for now. If I remember right, this is poor practice - they should haveautorelease
d session and declared the@property (retain)
.release
thesession
later. Not strictly poor practice, but certainly confusing and hard to read, and may lead to a bug in maintenance later (when someone loses track of theretain
-release
balance).In any event, you're right in that it's somewhat inconsistent with good memory management practices. It's hard to tell for sure, however, whether there's a definitive reason it's not released.