I am developing game in cocos2d-x 3.2 and my app memory increase with game progresses & it seems resources memory not releasing while scene replacing in cocos2d-x 3.2 , please help
You can use
Director::getInstance()->purgeCachedData();
to release those unused resources in the TextureCache, SpriteFrameCache, etc.
Without seeing some code this will be hard to answer correctly, but I'm going to venture a guess or two. Hopefully this'll help.
A common mistake is not using the ::create()
functions all Node
related classes have by default. Using ::create()
makes sure a Ref
is used, meaning the object will be reference counted, and the memory pretty much automatically freed up again after replacing the scene. So if you use new Scene()
somewhere in your code (and you don't release it in the destructor) instead of Scene::create()
you'll have a memory leak right there.
The same goes for Sprite
, Node
, Action
, basically anything. Always use their related ::create()
static function. If you have inherited from any of these classes, you can easily create your own create()
method by placing CREATE_FUNC(Player)
in the class definition, in the header. In this case Player
being the name of the class you created that extends an existing class, like Node
or Sprite
.
© 2022 - 2024 — McMap. All rights reserved.