Is it possible to force the garbage collector to run? In C# we can call GC.Collect() or something like that, but I haven’t seen anything similar in PlayCanvas.
When we transition from the menu to the game scene, we would like to make sure we don’t have any garbage leftover and the best place to have the garbage collector do it’s thing would be during the loading screen where any stuttering wouldn’t impact gameplay.
Forcing garbage collection means you have a memory issue and you don’t know what is causing it. Chase done the leak!
Same story with java code. A long time ago the Swing GUI of one of our projects eventually hogged up all the memory. I dug deep into optimising garbage collection. In the process, we found the leak in one of our layouting libs.
Quintessenz of the story: even if you tune garbage collection - you have to know what is causing your problems. And at that point you can fix the issue at the root
Of course, memory leaks should be traced and killed.
The technique I mentioned involved disabling the GC altogether, pre-allocating all variables, and forcing GC calls in-between scenes (or at other “reload” moments). This saved us 8ms per frame in overhead, in the game I was making. But, this was in Lua, which permits full GC control.
There are some code samples (I think the orbit camera code does this) where to minimise garbage, we use global variables to store temporary values such as vec3s which we can get away with as it is still single threaded.
Again, I’ve used that technique with Lua…was important to do with the GC disabled.
I’m still so new to JavaScript, though. I’m leaning on my experience with Unity (which has a similar editor), and Lua (which uses similar coding styles).
For now, I’m relying on objects placed in the editor…enabling and disabling, as needed.