Page 1 of 1

[RESOLVED] Memory leaks with tables ?

Posted: Sat Oct 15, 2016 2:19 pm
by Linkpy
Hello !

I'm making a framework on the top of Love, and I've been doing some example when I saw the tween lagging after a few seconds. Adding some debug info to the drawing, I can see the FPS dropping when the memory is expending. The problem is the memory does not stop growing, at a point where I can have 1 FPS for a simple love.graphics.print .

The GitHub repo : https://github.com/neoshadow-studio/ns-framework

You need to see the "example/scene_node.moon" file. Basically, it create a scene node and a tween (framework/scene_tree/tween.moon) and the FPS are dropping and the memory grows while the tween is processing. The memory extensive step of this process is the computation of the interpolated value (line 218) :

Code: Select all

v = @start_value + (@end_value - @start_value) * @.easing t

@reference.value = v
In the example the interpolated value is a vector (framework/scene_tree/transform.moon) which has the __add, __sub, __mul and __div meta-methods, which create a new instance of the Vector class. I don't really know if the leak come from here, and I don't know how to debug this and how to fix this problem.

Thanks for your help and your answers !

Re: Memory leaks with tables ?

Posted: Sat Oct 15, 2016 3:57 pm
by raidho36
The only reason GC couldn't collect an object is if it's referenced somewhere. So I suppose this creates memory islands or never lets go of vectors or something? Try inspecting generated Lua code.

Re: Memory leaks with tables ?

Posted: Sat Oct 15, 2016 9:39 pm
by pgimeno
There are more reasons why GC wouldn't collect. Try calling collectgarbage("collect") manually in update() to see if that helps; if it doesn't, then there's probably a bug in your code as radiho has indicated.

Sorry, I can't read .moon files.

Re: Memory leaks with tables ?

Posted: Sat Oct 15, 2016 10:15 pm
by raidho36
It does calls that already.

Re: Memory leaks with tables ?

Posted: Sun Oct 16, 2016 8:39 am
by Linkpy
pgimeno wrote:There are more reasons why GC wouldn't collect. Try calling collectgarbage("collect") manually in update() to see if that helps; if it doesn't, then there's probably a bug in your code as radiho has indicated.

Sorry, I can't read .moon files.
I already done this, and with this I was able to see the memory grows only when the tween is updating the value. But the memory don't move when the tween is waiting. And when the tween finish its job the controller removes it, but the memory doesn't decrease (but doesn't increase).

EDIT: Problem found and solved. Thanks for your answers.