Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory leakage:Received memory warning. Level=1 & 2 in cocos2d
    text
    copied!<p>I am newbie to cocos2d and facing memory problem.<br> I m getting memory warning level 1 &amp; 2. </p> <ol> <li><p>I have two scenes in my game. </p></li> <li><p>In first scene(mainmenu) I have button(on click it will replace scene with 2nd one i.e (StartMoving)) </p></li> <li><p>In StartMoving.h file I have intialized sprites,arrays(which I am deallocating in dealloc method) </p></li> <li><p>In my init method of StartMoving I have intialized background Image.(realeased in dealloc method) and going to the Allreset method. </p></li> <li><p>This is my code of the Allreset method. </p></li> </ol> <p>-(void)AllReset<br> {<br> while(x==5)<br> {<br> x=0;<br> [[CCDirector sharedDirector] replaceScene:[mainmenu scene]]; //Replacing scene when X=5</p> <pre><code>} CCLOG(@"%@: %@",NSStringFromSelector(_cmd),self); CCSprite *tra=[CCSprite spriteWithFile:@"tra.png"]; tra.position =ccp(800,115); [self addChild:tra z:0 tag:2]; [tra1 insertObject:tra atIndex:0]; //tra1 is NSMutablearray which is realeased in dealloc NSLog(@"tra is loaded...."); //[[SimpleAudioEngine sharedEngine] playEffect:@"police.wav"]; NSArray *name14 =[NSArray arrayWithObjects:@"app1.plist",@"app2.plist",@"app3.plist",@"app4.plist",@"app5.plist", nil]; NSArray *name24 =[NSArray arrayWithObjects:@"app1.png",@"app2.png",@"app3.png", @"app4.png",@"app5.png",nil]; NSArray *name34 =[NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",nil]; NSString *file14=[name14 objectAtIndex:x]; NSString *file24=[name24 objectAtIndex:x]; NSString *file34=[name34 objectAtIndex:x]; int frame[]={3, 7, 11, 4, 5}; float Fdelay[]={0.15, 0.2, 0.3, 0.1,0.5}; CCSpriteFrameCache *frameCache4 =[CCSpriteFrameCache sharedSpriteFrameCache]; [frameCache4 addSpriteFramesWithFile:file14]; CCSpriteBatchNode *danceSheet4 = [CCSpriteBatchNode batchNodeWithFile:file24]; [self addChild:danceSheet4]; CCSprite *sprite4 = [CCSprite node]; sprite4.position = ccp(395,155); [tra addChild:sprite4 z:1 tag:14]; NSMutableArray *animFrames4 = [NSMutableArray arrayWithCapacity:frame[x]]; for(int i = 1; i &lt;= frame[x]; i++) { NSString *namef4=[NSString stringWithFormat:@"%@%i.png",file34,i]; CCSpriteFrame *frame4 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:namef4]; [animFrames4 addObject:frame4]; } CCAnimation *anim4 = [CCAnimation animationWithFrames:animFrames4 delay:Fdelay[x]]; CCAnimate *animN4 = [CCAnimate actionWithAnimation:anim4]; CCRepeatForever *repeat4 = [CCRepeatForever actionWithAction:animN4]; [sprite4 runAction:repeat4]; id move= [CCMoveTo actionWithDuration:5.5f position:CGPointMake(240,115)]; id easeout=[CCEaseOut actionWithAction:move rate:1.5f]; id menudisp=[CCCallFuncN actionWithTarget:self selector:@selector(menudisplay:)]; [train1 runAction:[CCSequence actions:easeout,menudisp, nil]]; </code></pre> <p>}</p> <ol> <li><p>I have shown only one animation here but there are total 7 animation on the same sprite tra. </p></li> <li><p>When tra stops at a given point, menu label will be displayed. and when user taps label it starts moving in the same direction &amp; goes out of the screen. As soon as the whole sprite goes out of the screen one method is called which cleans up the memory of tra(I think with that only tra's children will be cleaned up. correct me if i am wrong..)</p></li> <li><p>After cleaning the memory it will again call Allreset method with increamented x value.</p></li> </ol> <p>`-(void)Incrementingx<br> { x++;<br> [self Allreset];<br> } </p> <h2>`</h2> <p>I have also used following things in applicationDidReceiveMemoryWarning method of appdelegate.m </p> <p>[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];<br> [[CCTextureCache sharedTextureCache] removeUnusedTextures];<br> //[[CCDirector sharedDirector] purgeCachedData]; //note this is commented</p> <p>Application is running perfectly fine on simulator but on device :(<br> please help me :( </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload