1

我在 mutableCopy 中有包含 Store 类型对象的数组。我释放数组,我释放数组之前释放所有对象吗?

NSMutableArray *stores=[[NSMutableArray alloc]init];
[stores addObject:[store1 mutableCopy]];
[stores addObject:[store2 mutableCopy]];
[stores addObject:[store3 mutableCopy]];
...
[stores release];
4

2 回答 2

6

If you don't use ARC, then you need to release your objects at some point, since the - mutableCopy method creates a new object with a retain count of +1. To avoid leaks, you should write:

[stores addObject:[[store1 mutableCopy] autorelease];

Now, there is no reason not to use ARC. If you use ARC, you're fine and you don't call - release on anything.

于 2013-03-18T17:29:40.463 回答
4

是的。

你应该使用:

[stores addObject:[[store1 mutableCopy] autorelease]];
于 2013-03-18T17:28:13.560 回答