And again my array of arrays ….
When I have an array “x” that contains multiple instances of an array “y”, how do I clear/release it without risking memory leaks?
are the following calls sufficient?
(a) clearing the array
[x removeAllObjects];
(b) releasing the array
[x release];
or do I need to enumerate the array, such as:
(c) clearing the array
for(int i=0;i<x.count;i++)
[[x objectAtIndex:i] release];
[x removeAllObjects];
(d) releasing the array
for(int i=0;i<x.count;i++)
[[x objectAtIndex:i] release];
[x release];
thanks in advance
(b) Should suffice. The array’s deallocator will release all contained objects, with a release for every retain (so multiple instances will be released as many times as they were added).
Never do
[[x objectAtIndex:i] release]— you haven’t retained the returned object, so you will muck up its retain count by releasing it.