Hi there !
I’ve been working on my game for a little time now and I’ve come to the point where I really need to take care of how I manage the memory in order to prevent memory leaks.
In order to clearly understand what I’d have to do, I’ve made few tests with the famous monitorMem() function in a new main.lua file :
[lua]local rectangle;
local function createRectangle()
rectangle = display.newRect(0,0,100,100);
rectangle:setFillColor(255,255,255,255)
end
local function removeRectangle()
rectangle:removeSelf();
rectangle = nil;
end
local timer2 = timer.performWithDelay(1000, createRectangle)
local timer = timer.performWithDelay(2000, removeRectangle)
local monitorMem = function()
collectgarbage()
print("MemUsage: " … collectgarbage(“count”))
local textMem = system.getInfo(“textureMemoryUsed”) / 1000000
print( "TexMem: " … textMem )
end
Runtime:addEventListener(“enterFrame”, monitorMem) [/lua]
From what I’ve seen, when I launch the app, the memusage starts at 106.75, when the rectangle is created, it goes up to 106.39 and then, once the rectangle is being deleted, it goes down to 105.875…
So… here are my questions :
-
Am I doing my test right ? Because I don’t understand the logic : when there is nothing loaded, the mem usage seems to be highter than once display objects are displayed.
-
When I remove display objects and clean my variables, is the memory supposed to go back exactly at its initial test ?
-
Bonus question : when I’m using the storyboard API, once a scene is purged, is the memory usage supposed to go back at its initial state ? Because right now, in my game, even if I remove all the displayed object, remove all the event listener, nil all the variables, it does reduce the memory usage, but there’s still a little bit more memory than before.
Thank you in advance, and sorry if I’m not clear enough !