See this code below - memory leak happens with rects, images and sprites.
Just accessing the image.path property is enough to make it kick in.
Comment out lines 19 and 20 to see how the memory usage remains stable, despite creating and deleting 100 rects per frame.
[lua]--------------------------------------------------------------
– SET UP EVERYTHING -----------------------------------------
– Memory text display
local memoryText = display.newText(‘00 00.00 000’,10,0, ‘Helvetica’, 20)
memoryText.x = 100
memoryText.y = 50
– ENTERFRAME ------------------------------------------------
local function enterFrame( event )
– Create a ton of images (shows up the leak a lot easier!)
for i = 1, 100 do
local rect = display.newRect( 0, 0, 100, 100 )
– Get rect path - comment out these two lines and see how the memory remains stable
local rectPath = rect.path
rectPath = nil
rect:removeSelf()
end
– Clean memory every single frame, twice over!
collectgarbage( “collect” )
timer.performWithDelay( 1, function() collectgarbage( “collect” ) ; end )
– Update the memory display - watch this count up slowly
memoryText.text = tostring( math.floor( collectgarbage( “count” ) ) )
memoryText:toFront()
end
– LET’S GO! -------------------------------------------------
Runtime:addEventListener(‘enterFrame’, enterFrame )[/lua]