I’ve got:
id<EnemyUpdate> enemies[6][10];
And I initialize my custom class using:
// init
enemies[row][col] = [[MyenemyClass alloc]init];
//..
-(void) dealloc{
[super dealloc]
// I want to release the 2d array here
}
Now, how would I release my objects later (in the dealloc method) in the 2-d array? By calling free(enemies[row][col]) doesn’t enter the dealloc method in the class. I don’t want to use autorelease by the way. How should I do it?
You should loop over them and release them one by one:
Remember that
autoreleaseMUST not be used in this situation: since objects are stored in an unmanaged object (a C array) an autorelease would cause a zombie object, since there is no one else retaining the object. What I mean is that you can’t doas you would do normally when adding then items to an
NSMutableArraybecause there is no retain count increase when setting a managed object in a C array, so object would be released but pointer in the array would keep pointing to garbage and mostly crash when you try to use it.Note that if you are working in an ARC environment this won’t work.