Puzzled by a potential memory leak

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: Puzzled by a potential memory leak

Post by Sasha264 »

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?
  1. 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.
  2. 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.
  3. The third parameter sets the maximum time each frame for garbage collection to be done.
  4. 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.
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Puzzled by a potential memory leak

Post by UnixRoot »

I think my problem could be LuaJIT and/or FFI related. I just found this post with almost the same behavior.

viewtopic.php?t=91198

I have some similar problems like @grump had.

If I run

randomFunction1()
randomFunction2()

it produces a lot of garbage and runs slow. If I instead run

randomFunction2()
randomFunction1()

It's fast again and the garbage doesn't go crazy.

Oh boy, I really start to hate the unpredictable and strange behavior of LuaJIT.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Puzzled by a potential memory leak

Post by pgimeno »

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.
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Puzzled by a potential memory leak

Post by UnixRoot »

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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 18 guests