I have gone through the following question.
Objective C - Where do you dealloc global static variables?
But the question is related on static variables. It has something different situation then mine.
I have following code in application.
//.h file
#import "cocos2d.h"
#import "something.h"
#import "myLayer.h"
#import "LayerData.h"
// i have taken this variables as global
// because two different classes are simultaneously accessing it
myLayer *myCurrentLayer;
LayerData *boxLayerData[10][12];
@interface one
// my class definition here
@end
@interface two
// my second class definition here
@end
//------------------------------------------------
@implementation one
// my class constructor here.
-(id)init{
myCurrentLayer=[[myLayer alloc] init];
// boxLayerData is initialized with objects
}
@end
@implementation two
// second class constructor
-(id)init{
[myCurrentLayer setPosition:ccp(10,20)];
[self schedule something for movements];
}
@end
//------------------------------------------------
OK. My confusion is "how to dealloc 120 sized "LayerData *boxLayerData[10][12];" array ?"
The same answer applies to global as it is to static. If you need the data for the entire application lifecycle, just leave it as it is and the memory will be reclaimed by the OS when the app terminates. If you need to release the object during the application's execution, you can loop through the array and call release on each object.
Something like this:
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 12; j++)
{
LayerData *data = boxLayerData[i][j];
[data release], data = nil;
}
}