Memory is not freed when Replacescene in cocos2d-x 3.2

I am developing the game in cocos2d-x 3.2, and the memory increase of the application with the game is progressing, and it seems that the resource memory is not freed up when replacing the scene in cocos2d-x 3.2, please help

+8
memory-management
source share
2 answers

you can use

Director::getInstance()->purgeCachedData(); 

to free these unused resources in TextureCache, SpriteFrameCache, etc.

0
source share

Without seeing any code, it will be difficult to answer correctly, but I'm going to risk a guess or two. Hope this helps.

A common mistake is not to use the ::create() functions, which all related Node classes have by default. Using ::create() , make sure that Ref used, which means that the object will be counted by reference, and the memory will automatically be freed after replacing the scene. Therefore, if you use new Scene() somewhere in your code (and you do not release it in the destructor) instead of Scene::create() , you will have a memory leak right there.

The same can be said about Sprite , Node , Action , basically anything. Always use the associated static function ::create() . 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 is the name of the class you created that extends an existing class, such as Node or Sprite .

0
source share

All Articles