c++ - Cocos2d replaceScene not releasing the old scene -


i have box2d-cocos2d game has several levels. levels layers use box2d features inherited class. example first layer looks like:

level1layer : box2dlevel : box2dlayer : cclayer : ccnode : nsobject 

my problem layer not releasing when should.for example if replay level code:

[[ccdirector shareddirector] replacescene:[cctransitionfade transitionwithduration:0.5f scene:[[self class] node]]]; 

then memory footprint increases.the same thing happens if have circle menu -> level 1 -> menu -> level 1 , app crashes after time because insufficient memory.i tracked dealloc methods nslogs, every dealloc method called, when replace scene. log looks like:

*** dealloc ***<level1layer = 0x1cdcfe70 | tag = -1> 2013-08-26 12:05:57.089 myapp[6334:907]  ***box2dlevel dealloc ***<level1layer = 0x1cdcfe70 | tag = -1> 2013-08-26 12:05:57.093 myapp[6334:907] ***box2dlayer dealloc *** <level1layer = 0x1cdcfe70 | tag = -1>  

i'm stuck, because on iphone 4 after playing 3 levels app crashes. how can solve problem? solutions , pointers appreciated.

level 1 dealloc:

-(void)dealloc{     nslog(@"\n*** dealloc ***%@",self);     [self removeallchildrenwithcleanup:yes];     [super dealloc]; } 

box2dlevel dealloc:

-(void) dealloc{     nslog(@"\n***box2dlevel dealloc ***%@",self);     [self removechild:_label cleanup:yes];     [self removechild:labelforcoins cleanup:yes];     [self removechild:labelfortime cleanup:yes];     [self removechild:freezecountdown cleanup:yes];     [self removechild:freezedmask cleanup:yes];     [self removechild:_background cleanup:yes];     [self removechild:darklayer cleanup:yes];     [self removechild:flashlayer cleanup:yes];     [self removechild:skillsmenu cleanup:yes];     [arrayforobjects release];     [skillsmenuarray release];     [super dealloc]; } 

box2dlayer dealloc:

-(void) dealloc {     nslog(@"***box2dlayer dealloc ***\n%@",self);     if (debugdraw) {         delete debugdraw;         debugdraw = null;     }     if (mousejoint) {         world->destroyjoint(mousejoint);         mousejoint = null;     }     if (groundbody) {         world->destroybody(groundbody);         groundbody = null;     }     if (referencebody) {         world->destroybody(referencebody);         referencebody = null;     }     if (bombsensor) {         world->destroybody(bombsensor);         bombsensor = null;     }     if (lasersensor) {         world->destroybody(lasersensor);         lasersensor = null;     }     if (_contactlistener) {         free(_contactlistener);         _contactlistener = null;     }     [self removechild:_obj cleanup:yes];     [super dealloc];     nslog(@"\n***box2dlayer superclass deallocated"); 

try using [level1layer scene] instead of [[self class] node] (so sample project it)


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -