gpt4 book ai didi

iphone - NSMutableArray 的 -removeLastObject 是否释放该对象?

转载 作者:行者123 更新时间:2023-12-03 20:24:51 25 4
gpt4 key购买 nike

我正在讨论 NSMutableArray 的 -removeAllObjects、-removeLastObject 等方法。文档只说这些方法从数组中“删除”对象。被移除的对象是否被释放?

最佳答案

是的,确实如此。任何删除都会调用已删除的 NSObject 的释放。

NSArray class reference指定:

Arrays maintain strong references to their contents—in a managed memory environment, each object receives a retain message before its id is added to the array and a release message when it is removed from the array or when the array is deallocated. If you want a collection with different object ownership semantics, consider using CFArray Reference, NSPointerArray, or NSHashTable instead.

关于iphone - NSMutableArray 的 -removeLastObject 是否释放该对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1391823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com