I have isolated this piece of exampled code as the culprit that causes my App to keep gobbling up more and more memory until the App freezes and halts. As best I know, I have nilled out the display group and forced garbage collection and am looking for advice on this.
As you keep hitting the “OK” button you will see the memory use incrementing.
Bug or bad programming?
[code]
– MemLeak1 - a test of display group display taking up incremental system memory
local bkg = display.newRect( 0, 20, display.contentWidth, display.contentHeight )
bkg:setFillColor( 255, 255, 255 )
local box = display.newRect( 100, 50, 120, 310 )
box:setFillColor( 200, 200, 200 )
local textBox = display.newText( “”, 180, 410, native.systemFont, 16 )
textBox:setTextColor( 0, 0, 0 )
local listData = {} – populate wth 200 numbers
for idx = 1, 200 do
listData[idx] = idx
end
– generate a new listGroup object
local listGroup = display.newGroup()
local startIdx = -13
local goBtn = display.newGroup()
goBtn.x = 130
goBtn.y = 366
local boxBtn = display.newRect( 0, 0, 60, 40 )
boxBtn:setFillColor( 242, 236, 160 )
goBtn:insert( boxBtn )
local okBtn = display.newText( “OK”, 12, 2, native.systemFontBold, 24 )
okBtn:setTextColor( 0, 0, 0 )
goBtn:insert( okBtn )
local function renderListData()
– clear out any previous display group
listGroup:removeSelf()
listGroup = nil
listGroup = display.newGroup()
local lastY = 52 – property to track current position
local newCell, lbl0
– in this section, build a newCell display group that holds one line of data to display.
for currentIdx = startIdx, startIdx + 14 do
newCell = display.newGroup()
newCell.x = 110
newCell.y = lastY
lastY = lastY + 20
lbl0 = display.newText( listData[currentIdx], 2, 2, native.systemFont, 14 )
lbl0:setTextColor( 0, 0, 0 )
newCell:insert( lbl0 )
lbl0 = nil
listGroup:insert( newCell )
newCell = nil
end
end
local function boxBtnListener()
startIdx = startIdx + 14
if ( startIdx > 186 ) then startIdx = 1 end
renderListData()
collectgarbage(“collect”)
txt0 = "System Memory : " … collectgarbage(“count”) – gets the memory used by the LUA code
textBox.text = txt0
end
boxBtn:addEventListener(“tap”, boxBtnListener )
[/code] [import]uid: 6114 topic_id: 2742 reply_id: 302742[/import]