I'm puzzled by the behavior of Love, or more precisely lua, on my current game.
I have noticed a memory leak in my project, which can be fixed my running the garbage collector manually.
To describe the issue: when I load meshes for my custom 3D project, then run Dear ImGui (via cimgui) to render my debug UI, the result of collectgarbage( "count" ) gains 1mb every seconds, if not more.
Below are just love.graphics.print of the output of collectgarbage("count") every frame:
- Only running ImGui, no meshes:
- Only loading my meshes, no ImGui:
- Loading meshes, then running ImGui:
Any suggestion on what could be happening or how to investigate it further ?
I'm not sure what to think about this issue, where it comes from or why it happens.
Details I can add:
- My mesh files are just lua file, with are a big table containing the vertices and a map to use with newMesh().
- My mesh file are loaded during onLoad() and cached in a local table in my main.lua file.
- My mesh file are loading by using love.filesystem.load() and not a require.
- ImGui Update() and NewFrame() run during the love love.update() function, then Render() and RenderDrawLists() during love.draw().
- I don't draw any UI with ImGui, just call newFrame().
- If I don't call imgui.newFrame() while the meshes are loaded, no leak (see gif above).
- The leak can be cleared by calling collectgarbage( "collect" ), but it needs to happen often and manually. Lua doesn't clean it by itself even after a while.
- If I only load a sub-set of the full list of meshes, I can see the memory going up still but it gets garbage collected after a while.
The threshold seems to change depending on how much memory/meshes I load in first place. The memory still goes up quite high however for no specific reason.