Hey guys, I got a question not sure how exactly the GC perform as my game lags a bit over long period of time.
Please see if there is any memory leak with the following code or if there is anything I can do to improve it.
local list = {}
local counter = 0
local function render( event )
counter = counter + 1
local graphic
if counter == 5 then
graphic = display.newImage(“agraphic.png”)
graphic.randomAttribute = “SOMETHING”
list[#list + 1] = graphic
counter = 0
end
local i = 1
while i <= #list do
graphic.alpha = graphic.alpha - 0.1
if graphic.alpha < 0.2 then
graphic:removeSelf()
– Do I need to set graphic to nil ? Does graphic go get GCed after table removes it?
– Do I need to set randomAttribute to nil or would that make the whole graphic to persist in memory even if table removes it?
table.remove(list, i)
i = i - 1
end
i = i + 1
end
end
Runtime:addEventListener(“enterFrame”, render) [import]uid: 6066 topic_id: 2162 reply_id: 302162[/import]