Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dealloc not fired when replacing scenes in Cocos2d

For some reason the dealloc of my CCLayer is not fired when replacing the scene. Here is the code to replace the scene:

[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:2.0f scene:[HelloWorld scene]]];

The above code is triggered when I press a button.

I have placed a NSLog inside the dealloc method which is never triggered.

UPDATE 1:

I ended up solving the problem by manually releasing the memory just before replacing the scene.

like image 632
azamsharp Avatar asked Mar 08 '11 17:03

azamsharp


1 Answers

When I first time begun to use cocos2d I had encountered this exactly same problem. In my case I'm added as targeted delegate the self and that means that reference count to the self was increased.

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:2]swallowsTouches:NO];

And I solved this by removing all delegates(also you can specify particular delegate) :

[[CCTouchDispatcher sharedDispatcher] removeAllDelegates];

like image 51
gixdev Avatar answered Sep 28 '22 23:09

gixdev