The following code removes and adds an image to the screen (when the blue button is pressed).
It also prints memory usage to the terminal.
Looks like memory is increasing on every press , although the image is removed and dereferenced (lines 36-37)…
Another strange thing is that if you set image scale to be 0.25 (just un-remark lines 43-44), memory seems to stay the same…
Is there a memory leak here or is it a problem in the collectgarbage( “count” ) method?
Is it a bug in my code or in Corona’s SDK?
The memory leak in this sample is negligible, but the code here is the base for my state machine where the memory leak becomes noticible.
Appriciate any help / info on this issue,
Thanks,
EZ
[code]
– vars local
local main_sprt = nil
local img_sprt = nil
local big_btn = nil
– forward declerations
local tapCb
– init
local function init()
– main_sprt
main_sprt = display.newGroup()
– big_btn
big_btn = display.newRect( 0, 0, 128, 128 )
big_btn:setFillColor( 0, 0, 255 )
big_btn.x = 0.5 * display.contentWidth
big_btn.y = display.contentHeight - big_btn.height
big_btn:addEventListener( “tap”, tapCb )
end
– tapCb
function tapCb( evt )
– remove img
if ( img_sprt ~= nil ) then
–img_sprt:removeSelf()
main_sprt:remove( img_sprt )
img_sprt = nil
end
– insert img
img_sprt = display.newImage( “Default.png” )
img_sprt.x = 0.5 * display.contentWidth + math.floor( -50 + 100 * math.random() )
–img_sprt.xScale = 0.25
–img_sprt.yScale = 0.25
main_sprt:insert( img_sprt )
– collecg garbage
collectgarbage( “collect” )
– print memory usage
local memUsage_str = string.format( “memUsage = %.3f KB”, collectgarbage( “count” ) )
print( memUsage_str )
end
–##################################################################################################
– START
–##################################################################################################
init()
[/code] [import]uid: 9536 topic_id: 4295 reply_id: 304295[/import]
[import]uid: 9536 topic_id: 4295 reply_id: 13413[/import]
