It looks like you're new here. If you want to get involved, click one of these buttons!
collectgarbage() collectgarbage() collectgarbage() collectgarbage() local mem1 = collectgarbage("count") -- initial memory usage -- create 3 levels of hierarchy where each level has 20 children (= 20*20*20 sprites) local s0 = Sprite.new() -- this will be the root for i=1,20 do local s1 = Sprite.new() for j=1,20 do local s2 = Sprite.new() for k=1,20 do local s3 = Sprite.new() s2:addChild(s3) end s1:addChild(s2) end s0:addChild(s1) end stage:addChild(s0) -- add the root of this hierarchy to the stage collectgarbage() collectgarbage() collectgarbage() collectgarbage() local mem2 = collectgarbage("count") -- memory usage after creating 8000 sprites s0:removeFromParent() -- detach from the stage and make it nil s0 = nil collectgarbage() collectgarbage() collectgarbage() collectgarbage() local mem3 = collectgarbage("count") -- memory usage after detaching the hierarchy from the stage print(mem1, mem2, mem3) |
58.28125 1539.421875 59.1982421875 |
Likes: ar2rsawseen, phongtt, hgvyas123, GregBUG, alexzheng
Comments
Btw, in Lua, even if you delete all the fields of a table, the table continues to occupy some memory space.
Likes: AlexRu
Likes: atilim
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Good memory management should be the cornerstone of ANY app, and I'd recommend all developers to make good use of the collectgarbage() function to make sure they aren't loosing any memory unexpectedly.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
so i just ask here.
i was testing out if my app is creating memleaks, and so i added
print (collectgarbage("count"))
to it.
i was wondering of constantly growing up mem usage, so i tried to find out what it is, and all that is left now from the app is this:
function onEnterFrame()
print (collectgarbage("count"))
end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
and even only with this there is still a growing memory usage.
or is it just the consolebuffer or something?
i think is related to print function... (or as you said console buffer)
try this...
function onEnterFrame()
print (collectgarbage("count"))
collectgarbage() -- clean memory garbage
end
and no memory grow...
i don't know if it's me
but Lua garbage collector is driving me crazy....
(yes... i'm memory paranoid)
b-(
ciao,
Gianluca
www.tntengine.com
It's totally related to Lua. In print function, the number returned from collectgarbage("count") is converted to string and each _unique_ string consumes some memory until they are collected.
Change the print(collectgarbage("count")) to print(math.floor(collectgarbage("count"))) and then you can see the memory remains same.
Likes: techdojo
www.tntengine.com
ty, so i now all is fine
small extra question:
should i just put collectgarbage() into the onEnterFrame event function?
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I think It will good if "Memory usage" subchapter will in Ultimate Guide.
May anybody explain me why call collectgarbage() for 4 times in gc()??
http://www.giderosmobile.com/forum/discussion/comment/5427