Hello
In my app I have a timer which ticks every 0.01 second. The time label is a group of images - I’ve got images for 1,2,3 and so on. each time timer ticks I’m removing the old group and creating new one. But I’ve noticed that simulator memory is constantly growing as my labels created and removed, and its growing really fast. Here is the code example
function makeTimeLabel( time )
local timeLabel = display.newGroup()
-- calculating minutes, seconds and milliseconds
local hours = math.floor( time / ( 3600 \* 1000 ) )
time = time - hours \* 3600 \* 1000
local minutes = math.floor( time / ( 60 \* 1000 ) )
time = time - minutes \* 60 \* 1000
local seconds = math.floor( time / 1000 )
time = time - seconds \* 1000
local milliSecs = (time % 1000) / 10
-- uiutils.makeNumber returns group of images which represents number
local lblHours = uiutils.makeNumber( hours, digits )
local lblMinutes = uiutils.makeNumber( minutes, digits )
local lblSeconds = uiutils.makeNumber( seconds, digits )
local lblMillisecs = uiutils.makeNumber( milliSecs, digits )
local minsSeparator = display.newImage( "colon\_text.png" )
local secsSeparator = display.newImage( "colon\_text.png" )
local millisecsSeparator = display.newImage( "colon\_text.png" )
lblHours.x = 0
minsSeparator.x = lblHours.x + lblHours.width
lblMinutes.x = minsSeparator.x + minsSeparator.width
secsSeparator.x = lblMinutes.x + lblMinutes.width
lblSeconds.x = secsSeparator.x + secsSeparator.width
millisecsSeparator.x = lblSeconds.x + lblSeconds.width
lblMillisecs.x = millisecsSeparator.x + millisecsSeparator.width
timeLabel:insert( lblHours )
timeLabel:insert( lblMinutes )
timeLabel:insert( lblSeconds )
timeLabel:insert( lblMillisecs )
timeLabel:insert( minsSeparator )
timeLabel:insert( secsSeparator )
timeLabel:insert( millisecsSeparator )
return timeLabel
end
function updateTimeLabel()
updateGameTime()
-- removing old timer label
**if( getGameScreen().lblTimer ~= nil ) then
getGameScreen().lblTimer:removeSelf()
getGameScreen().lblTimer = nil
end**
-- making label
local timeLabel = makeTimeLabel( getGameScreen().time )
-- setting new label
timeLabel.x = getGameScreen().back.x - 140
timeLabel.y = getGameScreen().header.back.y - 42
timeLabel.xScale = 0.5
timeLabel.yScale = 0.7
getGameScreen().lblTimer = timeLabel
end
In bold you can see the code which is assumed to clean and remove the old label group from the memory. But for some reasons mnemory is still growing. What is correct approach to remove group (which can also contain groups and on…) and keep memory in reasonable size? [import]uid: 31161 topic_id: 8619 reply_id: 308619[/import]