Hi,
I’m having memory problems in all my projects and after reading several posts, I can’t fix them.
My game have this this structure:
The size legend is the memory size allocated while the game scene is running and after interact with all elements of the scene (all creates, particles etc.)
In the loader scene I preload the sounds(AudioEngine) and textures(TexturePacker pvr.ccz) needed in the MainMenu, so the memory size should be always around the same (126MB).
After going to the MainScene, with everything loaded and created all sprites, etc. The size of the memory in the MainMenu is 177MB (ok).
The problem start when I go from the MainMenu to any of the games. I’m removing the textures that I don’t need (the ones I preload in the LoaderScene to use in the MenuScene) in the destructor of the MenuScene. I also uncache all sounds before creating the new scene and I preload the textures and the sounds needed in the game selected. The memory increases to 196MB, having removed 2 big texture packs and preload only a small one…
Going back to the MainMenu, I remove all textures preloaded for this game and sounds, and preload again the same textures and sounds I preloaded at the begining in the LoaderScene. The size should be the same as the first time (177MB) but not, now is 198MB!
Going to the second game, if I start the game again, the second game is 187MB and going back to the menu is 193MB, it happen the same. But if I open both games and going back to the menu, the difference its summed, and I have 6 games!
After running all 6 games and going back to the MainMenu, the memory is 340MB vs the 177MB of the first time.
I want to provide as much info as I can, so the way I’m doing all is as follows:
I preload the audio files this way:
AudioEngine::preload("Sounds/sound1.mp3");
I preload the textures like this:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("menu1.plist", "menu1.pvr.ccz");
The size of this texture file, for example, is 1817x1845 (I’ve read that I should use 1024x1024 npot pvr.ccz but not sure about the improvements that it will have and I have to split the textures in more files, but in case that is very important I can do it with all my texture packs. What do you think?).
All sprites and particles I create them this way:
File.h:
public:
Node* Nodo1;
Sprite* Logo;
.
.
private:
dragonBones::CCArmatureDisplay* Spider;
ParticleSystemQuad *rain;
.
.
File.cpp:
//Sprites
Logo = Sprite::createWithSpriteFrameName("Logo.png");
addChild(Logo,4);
//Particles
rain = ParticleRain::create();
rain->setTexture( Director::getInstance()->getTextureCache()->addImage("Particulas/fire.png") );
addChild(rain,12);
//Dragonbones
auto fac = dragonBones::CCFactory::getFactory();
fac->loadDragonBonesData("Anim1_ske.json","Anim1");
fac->loadTextureAtlasData("Anim1_tex.json","Anim1");
Spider = fac->buildArmatureDisplay("ArmatureSpider");
addChild(Spider,5);
From the MainMenu, If I choose a minigame, I preload the sounds and textures that I will need before creating the new scene, and release the sounds and textures needed in the MainMenu in the destructor:
MainMenu.cpp:
AudioEngine::uncacheAll();
AudioEngine::preload("Sounds/hit.mp3");
...
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("game1.plist", "game1.pvr.ccz");
if (scene2)
{
Director::getInstance()->replaceScene(TransitionFade::create(0.5f, scene2, Color3B::BLACK));
}
MainMenu::~MainMenu()
{
//Dragonbones
if (Spider){
this->removeChild(Spider);
Spider->dispose();
dragonBones::BaseObject::clearPool();
auto fac = dragonBones::CCFactory::getFactory();
fac->removeDragonBonesData("Spider",true);
fac->removeTextureAtlasData("Spider",true);
}
//Nodes (Layers, Sprites...)
if(Logo){
Logo->stopAllActions();
Logo->removeFromParentAndCleanup(true);
}
//Particles
if(rain){
rain->stopSystem();
rain->stopAllActions();
rain->removeFromParentAndCleanup(true);
}
this->stopAllActions();
this->unscheduleUpdate();
this->removeAllChildrenWithCleanup(true);
//Textures
SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("menu1.plist");
}
What I’m doing wrong or missing?
Please help me!