Correct way to clear/release an array of arrays

Posted by iFloh on Stack Overflow See other posts from Stack Overflow or by iFloh
Published on 2010-05-16T15:38:57Z Indexed on 2010/05/16 15:40 UTC
Read the original article Hit count: 154

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone