Memory not releasing when Replacescene in cocos2d-x 3.2
Asked Answered
P

2

7

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

Panaggio answered 17/7, 2015 at 9:25 Comment(3)
can you please share some CodePhlegmy
Code would make helping you out a lot easier, but check out this previous question .Amaya
I solve most of my issues by making auto-release every those object which was initialized using new operator , plus at every scene transitions i remove every objects of that scene by pushing them in array .. that way it worked .. i don't think its proper way to release memory but it works.Panaggio
B
0

You can use

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

to release those unused resources in the TextureCache, SpriteFrameCache, etc.

Brose answered 12/11, 2015 at 7:48 Comment(0)
I
0

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.

Isabelisabelita answered 11/10, 2016 at 13:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.