I recently finished a game, and after a final wave of optimization I noticed that there was periodic half-second spike, every 15 seconds. I managed to trace this issue back to the GC, as every time there was a lag spike, some memory was release. The memory usage during this 15s period of time would constantly grow, only when the update method of my app is being called.
Of course I went through the whole thing and I don’t make any new objects, functions or arrays in it, except for quite a few cc.p objects, which I understand should be optimized for JIT or something. I have a lot of cc.p() objects, because each frame, all objects on the screen need to move and there’s perhaps 20 of them. Is my only option creating less objects to being with? The V8 and Spidermonkey engines seem to handle this way better in the browsers.
You can call GC yourself in JSB by using cc.sys.garbageCollect(), so you can manage to make GC in a frequency you want so that there won’t be very often memory usage piques
There is a way to reduce cc.p object creation, you can use property APIs which won’t create cc.p object while you move elements
node.x += dx;
node.y += dy;
At last, I admit that I’m not sure what’s the difference between the behavior of SpiderMonkey in JSB and in Firefox. We should have used the same thing, because it’s compiled directly from Firefox source.