Hello all,
My issue put simply is this : I create hundreds of display objects, and, upon removing them, my application’s memory does not reduce as it should when the objects are removed and garbage collection ( collectgarbage( “collect” ) ) is called.
Display object information setup:
local image\_sheet\_file = "test\_tile\_set.png" local options = { width = 32, height = 32, numFrames = 4, sheetContentWidth = 64, sheetContentHeight = 64, } sheet = graphics.newImageSheet( image\_sheet\_file, options )
Table storage for display objects:
object\_table = {}
Generation of display objects:
local function generate\_object(image\_sheet\_index, postion) local obj = display.newImage( sheet, image\_sheet\_index, postion.x, postion.y ) obj.id = #object\_table function obj.remv\_func() obj:removeSelf() obj = nil end return obj end
I call this function several times depending on the need, sometimes ~50 times:
object\_table[#object\_table+1] = {} object\_table[#object\_table].displayed\_object = generate\_object(image\_sheet\_index, postion) --position is a table containing the x and y coordinates --image\_sheet\_index is what I use to determine which frame from sheet to use
Removal of display objects:
object\_table[id].displayed\_object.remv\_func() object\_table[id] = nil --the "id" is relative to the object needing to be removed
I am concerned that I am not removing each display object properly in order for garbage collection to eliminate their memory. I am calling collectgarbage( “collect” ) manually and displaying collectgarbage( “count” ) before and after upon a key press for testing.
From what I understand the function “obj.remv_func()” should first remove the object from the display ( obj:removeSelf() ) and then nil it ( obj = nil ) which makes it eligible for garbage collection. Please let me know if my understanding is incorrect.