Replacing scenes and memory

Hi, I have 2 scenes in my game and when my app starting it use 8 MB of RAM (I use Android Assistant to trace memory consumption), then I replace scene to other and consumption growth to 10 MB. But when I go back to first scene memory consumption is still 10 MB. I use this code to replace scenes:
@
CCDirector::sharedDirector()>replaceScene);
//—//
CCScene* MyScene::scene{
CCScene scen = CCScene::node;
MyScene
layer= new MyScene;
layer
>init();
layer~~>autorelease;
scen~~>addChild(layer, 1, 101);
//CCTransitionFade *trans = CCTransitionFade::transitionWithDuration(0.1f, scen);
return scen;
}
@

In both scenes I just create background sprite in init method. Its strangely, that when I replace scene first time I have waiting 1 second, but only in first time. Both scenes still in memory, but I don`t want this. Sorry for bad English

P.S. and why just one 350 KB sprite in other scene increase using memory on 2 MB? It`s code that I use:
@
sizeScene = CCDirector::sharedDirector()>getWinSize;
float scaleParam = sizeScene.width/640;
layerScale = CCLayer::node;
layerScale
>setScale(scaleParam);
this~~>addChild;
CCSprite* pSprite = CCSprite::spriteWithFile;
pSprite~~>setPosition(ccp(sizeScene.width/2, sizeScene.height/2) );
layerScale->addChild(pSprite, –3);
@

scene is not still in memory but your loaded sprites / textures YES.

and don’t refere to file size to know the texture memory usage, texture memory usage = width * height * 4 bytes.

ok, but how can I reloaded their from memory? I think sprites uses autorelease method, and removing from memory when I replace scene

you have multiple way to “release” the unused textures :

  • CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames() and CCTextureCache::sharedTextureCache()~~>removeUnusedTextures;
    ~~ CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFrameByName(“filename.plist”) and CCTextureCache::sharedTextureCache()->removeTextureForKey(“filename.png”)

the first solution is the “easier” but, in my apps i’m using the second one, which is better to know what is loading at a time.

But I create sprite without texture cache, isn`t it?
@
CCSprite* pSprite = CCSprite::spriteWithFile(“./Graphics/background.png”);
pSprite~~>setPosition );
layerScale~~>addChild(pSprite, –3);
@
or this method all the same added “./Graphics/background.png” to cache? and autorelease must delete CCSprite from cache or no?

the only way to not use the texture cache, is to load manually the texture and give it to your sprite.

in any other way (i think), you are using texture cache. so you have to cleanup texture cache/sprite cache.