NSData initWithContentsOfURL:不返回原始分配?
In the documentation of NSData
's initWithContentsOfURL:
, it says:
The returned object might be different than the original receiver.
What are the implications of that? It seems to imply that a standard "alloc/init" line could leak memory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类簇被最广泛认可的原因有几个:
使用这种形式不会引入泄漏。
它只是意味着您应该只使用
alloc
+init
调用的结果(而不是保留alloc
的结果),即无论如何,这都是一个好主意——即使没有明确记录。there are several reasons why - class clusters being the most publicly recognized:
no leaks are introduced using this form.
it just means that you should only use the result of the
alloc
+init
call (rather than holding onto the result ofalloc
), which is a good idea in any case -- even when not explicitly documented.