This is a simplified version of the problem that I am facing now. I made 2 empty CCScene 1 and 2 and added CCLayer 1 and 2 to their respective scene. I also added a touch function to switch from scene 1 to scene 2 using the CCDirector replaceplacecene.
However, dealloc was never called during a scene change.
// scene & layer 2 are exactly the same as 1 @implementation MainScene -(void)dealloc { NSLog(@"scene dealloc"); [super dealloc]; } -(id)init { self = [super init]; if (self) { layer = [[MainLayer alloc]init]; [self addChild:layer]; [layer release]; NSLog(@"test: %i", [layer retainCount]); //1 } return self; } @implementation MainLayer -(void)dealloc { NSLog(@"layer dealloced"); [super dealloc]; } -(id)init { self = [super init]; if (self) { self.isTouchEnabled = YES; NSLog(@"test %i", [self retainCount]); //1 } return self; } -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"test %i", [self retainCount]); //2 --> ???? [[CCDirector sharedDirector] replaceScene:[[SecScene alloc]init]]; }
in addition, NSLog reported that the level of the remainder of the layer is 2 when I touch the screen. Is this even happening? Can someone probably tell me what I did wrong, or is it just my misunderstanding that keepCount must be 0 before dealloc is called?
This problem causes my main game program to crash, just switching between different scenes / layers using only static sprites (and some minor actions) over and over again.
source share