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?
[import]uid: 31039 topic_id: 14058 reply_id: 314058[/import]

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 [import]uid: 48203 topic_id: 14058 reply_id: 51844[/import]

understood. thx’s [import]uid: 31039 topic_id: 14058 reply_id: 51879[/import]