Memory usage

local monitorMem = function()

collectgarbage()

print( "MemUsage: " … collectgarbage(“count”) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000

print( "TexMem: " … textMem )

end

Runtime:addEventListener( “enterFrame”, monitorMem )

Hi,

I used this code to monitor memory usage of my game.

On MemUsage it prints 550. Does that mean app is using 550mb of RAM or is it just something about memory leaking?

I use this code:

local function checkMemory()
    collectgarbage( “collect” )
    local memUsage_str = string.format( “MEMORY = %.3f KB”, collectgarbage( “count” ) )
    print( memUsage_str, “TEXTURE = “…(system.getInfo(“textureMemoryUsed”) / (1024 * 1024) )…” MB” )
 end
timer.performWithDelay( 5000, checkMemory, 0 )

collectgarbage(“count”) returns your lua memory in KBytes (1024 bytes).

system.getInfo(“textureMemroyUsed”) returns the amount of OpenGL memory in use in bytes.

Thanks guys :wink:

I used this to free up even more memory :smiley:
local freeMemory = timer.performWithDelay(800, function() collectgarbage(“collect”) end,0)

I use this code:

local function checkMemory()
    collectgarbage( “collect” )
    local memUsage_str = string.format( “MEMORY = %.3f KB”, collectgarbage( “count” ) )
    print( memUsage_str, “TEXTURE = “…(system.getInfo(“textureMemoryUsed”) / (1024 * 1024) )…” MB” )
 end
timer.performWithDelay( 5000, checkMemory, 0 )

collectgarbage(“count”) returns your lua memory in KBytes (1024 bytes).

system.getInfo(“textureMemroyUsed”) returns the amount of OpenGL memory in use in bytes.

Thanks guys :wink:

I used this to free up even more memory :smiley:
local freeMemory = timer.performWithDelay(800, function() collectgarbage(“collect”) end,0)