我有一个 -dealloc() 方法,我假设我可以用它来释放实例变量,我有另一个不在实例中的变量,而是一个类级别的变量,想知道我何时以及如何释放这个?我不能在实例方法 dealloc() 中做到这一点,对吗?下面的代码供参考(关于变量:levelHash):
@interface Level : CCNode
{
//Instance variables
PlayBackgroundLayer* playBGLayer;
PlayTilemapLayer* playTilemapLayer;
PlayUILayer* playUILayer;
PlayElementLayer* playElementLayer;
}
//Property declarations for instance variables
@property (nonatomic, retain) PlayBackgroundLayer* playBGLayer;
@property (nonatomic, retain) PlayTilemapLayer* playTilemapLayer;
@property (nonatomic, retain) PlayUILayer* playUILayer;
@property (nonatomic, retain) PlayElementLayer* playElementLayer;
//Static methods
+(void) Initialize: (NSString*) levelReference;
+(void) InitLevel: (NSString*) levelReference;
+(Level*) GetCurrentLevel;
@end
//static variables
NSMutableDictionary *levelHash;
和我的实现:
+(void) Initialize: (NSString*) levelReference
{
levelHash = [[NSMutableDictionary alloc] init];
[levelHash setObject:NSStringFromClass([LevelOne class]) forKey:@"1"];
//EG CALL IT [levelHash objectForKey:@"foo"];
//WHEN DO I CALL THIS??? [levelHash release];
}