UnixRoot wrote: ↑Sun May 14, 2023 10:00 am
If I collect every frame, the memory consumption stays at a stable level for hours, but it lags really bad. It's not a real leak, it's really a garbage problem.
Ok! Back to collecting garbage then =)
Have you tried tweaking the numbers?
The first number will be the 5 in collectgarbage("step", 5). It controls the amount of garbage collected in an unspecified way, so it can be tuned for each specific application.
The second number is the maximum number of collectgarbage("step", ...) calls that can be performed each frame. Fewer calls with a larger size will result in less total garbage collection time. More calls with a smaller size will result in more predictable garbage collection time per frame.
The third parameter sets the maximum time each frame for garbage collection to be done.
The fourth parameter, used in the Batteries manual_gc.lua, is the memory threshold after which a full collectgarbage() will be triggered, causing a massive stutter. However, if this only occurs like once in every 2 hours, it may not be a problem. This adds a layer of protection to the whole process.
There are some tips there for how to tweak JIT settings. I doubt you have a "diamond pattern" as in that thread, so maybe those tweaks are enough for you.
This actually helped a lot. It's not perfect, but the stuttering is gone and garbage production is now "only" 10 MB per minute, instead of almost 500 MB.