So I’ve got a game in which a lot of actors are spawned, at a rapid rate. They also get destroyed almost as fast.
Since the latest Rocket upgrade, I seem to get a massive slowdown after about a minute, until a garbage collection happens. We’re talking of an fps drop from 120 fps to ~20fps, then straight back up to 120. Looking at the object count at the top of the screen, we’re talking going from ~300k to ~450k until the gc comes into effect.
I can force a garbage collection by using the console command, ‘OBJ GC’, but I can’t find a way to automate that through script. When I execute a console command, using OBJ GC, I just get a crash.
Is there any way to modify to GC rate? Preferably through just script.
You should never ever allocate and destroy anything rapidly “At a rapid rate” - If you are doing this then you should be using a spare list. And reusing those allocations.
Also you cannot simply force a garbage collection any time you want. There are specific points in the update loop where it is possible.
GEngine->ForceGarbageCollection();
This occurs after all the tick groups have run. so NO you cant run it on a timer. You tell it to ignore its heuristic, and force a GC at the end of the current frame.
There’s a handy console command that will force garbage collection every frame. This is really useful for testing to make sure that you didn’t muck up your memory management: