Why does this code “leak” in the case where some data is stored within a display group?
Based on the doco here http://docs.coronalabs.com/guide/media/displayObjects/index.html#remove shouldn’t the “group.removeSelf()” work in this case???
local useArrayInstead = false function createTestGroup() if (not useArrayInstead) then -- Case 1: Use a display group testArrayOrGroup = display.newGroup() -- LEAKS!!! else -- Case 2: Use an array testArrayOrGroup = {} -- Does NOT Leak end for i=1,100 do table.insert(testArrayOrGroup, {a = "asdf", b = "adsfasdf", fn = function() print("xxxx") end }) for j=1,100 do table.insert(testArrayOrGroup[i], {a = "asdf", b = "adsfasdf"}) end end return testArrayOrGroup end function gcLuaLocalsTest() for i=1,10 do local myTestGroup = createTestGroup() if not useArrayInstead then myTestGroup:removeSelf() -- Does NOT work end myTestGroup = nil -- Does nothing collectgarbage() local memUsage\_str = string.format( "mem %.3fKB", collectgarbage( "count" ) ) print(i .. ", " .. memUsage\_str) end -- profiler.fullSnapshot() end gcLuaLocalsTest()
Console Output:
Copyright (C) 2009-2013 C o r o n a L a b s I n c . 2013-08-17 08:37:27.856 Corona Simulator[1580:707] Version: 2.0.0 2013-08-17 08:37:27.856 Corona Simulator[1580:707] Build: 2013.1178 2013-08-17 08:37:27.862 Corona Simulator[1580:707] The file sandbox for this project is located at the following folder: (/Users/Greg/Library/Application Support/Corona Simulator/memoryLeakTest-65AEC6564F32F1046AA9F1BABE8DDB7F) 2013-08-17 08:37:27.874 Corona Simulator[1580:707] 1, mem 1812.018KB 2013-08-17 08:37:27.879 Corona Simulator[1580:707] 2, mem 3446.236KB 2013-08-17 08:37:27.886 Corona Simulator[1580:707] 3, mem 5080.455KB 2013-08-17 08:37:27.893 Corona Simulator[1580:707] 4, mem 6714.674KB 2013-08-17 08:37:27.901 Corona Simulator[1580:707] 5, mem 8348.893KB 2013-08-17 08:37:27.910 Corona Simulator[1580:707] 6, mem 9983.111KB 2013-08-17 08:37:27.920 Corona Simulator[1580:707] 7, mem 11617.330KB 2013-08-17 08:37:27.932 Corona Simulator[1580:707] 8, mem 13251.799KB 2013-08-17 08:37:27.944 Corona Simulator[1580:707] 9, mem 14886.018KB 2013-08-17 08:37:27.957 Corona Simulator[1580:707] 10, mem 16520.236KB
