memusage

saw this function in a blog:

-----------------------------
local monitorMem = function()
-----------------------------

collectgarbage()
print( "MemUsage: " .. collectgarbage("count") )

local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000
print( "TexMem: " .. textMem )
end
---
Runtime:addEventListener( "enterFrame", monitorMem )

I'd like to know why the collectgarbage() is in the function ?

Doesn't that defeat the purpose of finding out if your program has a memory leak?

You want that in there to force Lua to perform the garbage collection. If you check the memory right before Lua invokes the garbage collection on its own you may be chasing phantom issues.

By forcing this call manually you can be sure that what you are checking is as good as it it's going to get, hence you can identify that there is an issue or not.

Remember, the garbage collector can only collect objects that YOU have properly discarded of and prepared to be collected.

Hope that helps,

Croisened

understood. thx's

views:1351 update:2011/10/7 17:24:19
corona forums © 2003-2011