基础函数的内存管理指南
虽然基础类的内存管理是一致的并且有记录,但我惊讶地发现(通过友好的 EXC_BAD_ACCESS )基础函数(例如 NSStringFromSelector() )似乎返回指向常量存储 - 至少该函数的文档中没有提到这一点。
该行为是否记录在某处?有没有一致的指导方针?
While memory management for the foundation classes are consistent and documented, i was surprised to find (via the friendly EXC_BAD_ACCESS
) that Foundation functions like e.g NSStringFromSelector()
seem to return pointers to constant storage - which is at least not mentioned in the documentation for the function.
Is that behaviour documented somewhere? Are there any consistent guidelines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些规则实际上与 Objective-C 方法的规则相同 - 如 这些核心基础功能的文档。
因此,在您的示例中,因为单词
alloc
、new
、create
或copy
不存在您获得的对象back 不属于您(它将具有静态存储或将自动释放)。The rules are really just the same as those for Objective-C methods - as is illustrated by these docs for the core foundation functions.
So in your example, because the words
alloc
,new
,create
orcopy
are not present the object you get back is not owned by you (it will either have static storage or will be autoreleased).