Page 1 of 1

How do i profile memory usage in love2d?

Posted: Fri Aug 24, 2012 3:17 am
by titangate
I have been using ProFi to profile the running time of functions, which has been helpful; but is there anyway to investigate the memory allocations/dellocations/usages?

thanks in advance :awesome:

Re: How do i profile memory usage in love2d?

Posted: Fri Aug 24, 2012 5:06 am
by Roland_Yonaba
Yes, there is.
Just use collectgarbage, passing it 'count' as argument.

Code: Select all

function love.draw()
   love.graphics.print('Memory actually used (in kB): ' .. collectgarbage('count'), 10,10)
end

Re: How do i profile memory usage in love2d?

Posted: Fri Aug 24, 2012 6:46 am
by Petunien
LÖVE does only use the memory of the Lua task?
It doesn't need more?

Re: How do i profile memory usage in love2d?

Posted: Fri Aug 24, 2012 2:46 pm
by Inny
collectgarbage('count') shows the amount of memory that Lua is responsible for (i.e. stored in the lua_state, and subject to garbage collection). If you're using threads, it won't show what the other threads are using, and it won't (shouldn't) show what Love is using internally. Though, anything love stores in the lua Registry, that stuff could be counted, depending on how it's stored.
Roland_Yonaba wrote:

Code: Select all

function love.draw()
   love.graphics.print('Memory actually used (in kB): ' .. collectgarbage('count'), 10,10)
end
And interesting note about displaying that number this way (string concat operator), is that it impacts memory usage, meaning that the rate of memory growth displayed will be faster than it would actually be without the display. So, don't freak out when your process is shooting through memory like it's going out of style. What should concern you more is how often a GC cycle happens, which you'll notice as a sudden drop in the amount of memory used. GC cycles have the biggest impact on performance.