views:

73

answers:

2

In Objective-c I have this:

SomeObject *values[3][3];

when deallocating, as in C++ should I release element by element?

Or if I do:

[values release];

is ok?

+7  A: 

release only applies to Objective-C objects. A C style array (like you have there) is just some stack memory.

In your case, it looks like you're using it to store 3x3=9 Objective-C objects in it. If you want to release them all, you need to do it element by element. The C++ analogy doesn't hold in this case because the array itself isn't an Objective-C object.

(If you were holding stuff in an NSMutableArray, the answer would be different. You should look into that by the way.)

quixoto
A: 

It is an array of pointers. Just values points to first object, so [values release] will release only first object. You have to release each object in array.

beefon
This is incorrect, [values release] will not release the first object in the array. But [values[0] release] will.
invariant
@invariant: This is incorrect, `[values[0] release]` will not release the first object in the *2D* array. But `[values[0][0] release]` will.
KennyTM