Cocos Creator 2.2 Game Freeze on browser

Cocos Creator 2.2 Game Freeze on browser

I have a really strange issue with my game. I developed a game that has fast-moving dynamic bodies, sensors, and colliders with some animated effects and sound effects. It has 40 levels. The game works really smooth with no issue until some levels like 30-35 levels, or if you play one level repetitively then it freezes about 10-12 times, then it freezes and I can not even close the tab of google chrome.No error no message only game freezes. I am using cocos creator 2.2. If anyone knows about this issue then please help me.

1 Like

I think, your game may be leaking memory.
Since 2.2, CC stops doing GC and you got to destroy objects yourself. (Haven’t tried 2.2 myself, but require to do GC manually is a bad move, I personally think )

May be you should check memory usage in chrome dev tools while your game is ruining.

And GL!!

Quote from official website

  • Starting with 2.2, we have enhanced the memory management mechanism. Now the cc.Node that is dynamically created by the code and independent of the scene node tree must be released by destroy() , otherwise the engine doesn’t know when to recycle such nodes. In addition, nodes that are manually removed from the scene need to unify destroy when they are not needed. If the node is managed via cc.NodePool , it is not affected.
    // Suppose testNode is a node in the scene, if it was manually removed from the scene, such as
    testNode.parent = null;
    // or
    // or
    // If testNode will be used again later, there is no need to manually destroy the node.
    // Otherwise it should be called manually

Thanks for the reply. I did destroy the nodes after they are not used in the scene. I checked the memory tool available in chrome but it does not have major changes after frequent scene changes. it seems normal but suddenly after a few minutes I played the game , it freezes at random time. I want to know how to release all nodes from memory before the next scene transition. I used some code to reduce the memory in the onDestroy() method but don’t see any effect of it.

Currently, I have used this code to solve the issue

            cc.find('Canvas').children.forEach(element => {

I don’t know if its feasible or not but I did this.

I see. You can also monitor object count from chrome dev tools.

I am not sure whether you have created/added/removed nodes dynamically. If so, all of them must be destroyed manually. If you need to add/remove the same types of nodes repeatedly, you may consider using NodePool.

The codes you wrote at OnDestroy will just destroy nodes which are direct children of the canvas node. I think you don’t need to do that as they are attached to the scene and they will be destroyed automatically by CC. However, there are still chances of unattached nodes floating in the memory. So, you must destroy them manually.

1 Like

just forgot to tell you that this will raise the error as node already destroyed.

The same problem happen with me am making instant game when i load new scene null reference appear it seem memory never released
Any good solution for that!

Some basic/simple check would be

  • search your codes where you remove nodes from a scene. for example, search for these keywords:

  • after you remove those nodes form their parents, you must call .destroy()

Please try that and hope it fixes your issues. Please feedback afterward. Good luck guys!

Yes I have created new nodes dynamically, I destroy them manually but need to recheck if all of them is destroyed or not.Can you have good example of using NodePool?

This is the cocoscreator official sample collection project with examples of how to use nodepool.

1 Like

thanks for the example , i will have a look and try to implement the concept in my game.