我有一个关于如何最好地管理数组指针以确保不会发生内存泄漏的问题。我有一个容器类 A 和一个复合类 B。两者都有一个数组属性,并且都对数组做自己的事情。但是容器是唯一暴露给公共 API 的类。所以我设置了 classA.someProperty,它在内部设置了 classB.someProperty,如下所示。我需要做什么样的清理工作?ARC 会自动为我解决这个问题吗?
class A
@property(nonatomic,strong) NSMutableArray* someProperty;
@property(nonatomic,strong) ClassB* classB;
Class B
@property(nonatomic,strong) NSMutableArray someProperty;
并在 A 类的实施中;
classB.someProperty = [self.someProperty mutableCopy]
//do some other work with self.someProperty
and in the implementation in Class B;
//do some work with self.someProperty [Includes modifications to the array]