Hi
This is an issue that is bothering me for a while. I also posted this on cocos2d forums but so far no help and decided to ask for help here as well.
So basically I have a MainMenuScene, which in turns creates a test layer. This layer is very simple as it only creates a score label and a button that is added to a menu. When this button is pressed the MainMenuScene is replaced by a blank scene and then the MainMenuScene is loaded again.
So far so good. However the problem is when I take a heapshot in the instruments each time the scene is reloaded, I get a heap increase of around 20kb. When I dig deeper in the extended view it seems the sprite and font from the testLayer aren't being released and yet the dealloc method from the layer is being called.
I also add ARC support to my files except core Cocos files. Could this be related in any way?
Here is the test layer:
@implementation TestLayer
-(id)init
{
self = [super initWithColor:ccc4(2,2,2,210)];
if (self != nil)
{
// ask director the the window size
CGSize s = [[CCDirector sharedDirector] winSize];
self.isTouchEnabled = YES;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber * n = [NSNumber numberWithInt:[SDCloudUserDefaults integerForKey:@"highscore"]];
NSString *string = [formatter stringFromNumber:n];
//score
CCLabelBMFont * scoreLabel = [CCLabelBMFont labelWithString:string fntFile:@"scoreFont.fnt" width:s.width alignment:kCCTextAlignmentCenter];
scoreLabel.position = ccp( POS_X(443), POS_Y(877) );
[self addChild:scoreLabel z:90];
//PLAY BUTTON
CCMenuItemSprite *playButton = [CCMenuItemSprite itemFromNormalSprite:[CCSprite spriteWithFile:@"play_up.png"]
selectedSprite:[CCSprite spriteWithFile:@"play_down.png"]
target:self
selector:@selector(Transition:)];
playButton.position = ccp( POS_X(380) , POS_Y(177));
menu = [CCMenu menuWithItems: playButton, nil];
menu.position = ccp(0, 0);
[self addChild: menu];
}
return self;
}
-(void) Transition:(ccTime) dt
{
[self unschedule:@selector(Transition:)];
[[SceneManager sharedSceneManager]RunSceneWithID:SCENE_LOADING:eCCTransitionCrossFade:1.0f];
}
- (void) dealloc
{
NSLog(@"%s",__FUNCTION__);
}
@end
So it seems to me that even though the dealloc methods are being called, the assets inside the layer aren't being released...I don't understand what is going on.
Any help would be much appreciated.