NSMutableArray:addObjectsFromArray 保留
我正在调用 [array addObjectsFromArray:dictionary.allValues] 每个复制的对象的保留计数都会增加吗? 我的理解是,当我执行 [array addObject:obj] 时,它将为我保留 obj ,直到我从数组中删除 obj 或释放数组本身。想知道它是否与 addObjectsFromArray 相同
谢谢。
I am calling [array addObjectsFromArray:dictionary.allValues]
Will each copied object have retain count incremented for it?
My understanding that when I do [array addObject:obj] , it will retain obj for me untill I delete obj from array or release array itself. Was wondering if its the same with addObjectsFromArray
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参考这个:
NSMutableArray 内存管理
关于对象创建方法,所有便捷方法(array:、arrayWithObjects :, arrayWithArray: 等)返回自动释放的对象。但是,它们相应的 init 方法(init:、initWithObjects:、initWithArray: 等)则不然 - 如果调用它们,则负责在返回的对象上调用release
refer this :
NSMutableArray memory management
Regarding the object creation methods, all of the convenience methods (array:, arrayWithObjects:, arrayWithArray:, etc.) return autoreleased objects. However, their corresponding init methods (init:, initWithObjects:, initWithArray:, etc.) do not - if you call them, you are responsible for calling release on the returned object
以 init、copy、add 等开头的函数总是会增加相应对象的保留计数器。如果您完成了 和 对象,您应该释放它 adterr 添加到 nsmutablearray
function that begin with init,copy,add etc always increments the retain counter of the corresponding object.If you are done with and object you should release it adterr adding to an nsmutablearray