Where's the memory leak here?

This routine to display a score event and remove it keeps adding to the texture memory. I can’t figure out why. Any suggestions?

When I run it, I get:
Texture memory = 246808 (before)
Texture memory = 247608 (after)
and it goes up every time. I tried it as msg.removeSelf() too. Same result.

[lua] local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)

– show score
local msg = display.newText( “+” … addScore, 0, 0, nil, 14 )
msg:setTextColor( 200, 200, 200, 255 )
msg:translate(t.x, t.y )
transition.to( msg, {time = 3000, alpha = 0}, function() msg:removeSelf() end)

local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)[/lua]

Thanks. [import]uid: 1560 topic_id: 2724 reply_id: 302724[/import]

try msg=nil inside the anonymous function

garbage is not collected *immediately*, unless you call GC cycle manually

set a timer and print TMem for 20 secs to see what happens

replace the seconf local mem with just mem= (you have already that local declared) [import]uid: 7356 topic_id: 2724 reply_id: 8111[/import]

Hi Dotnaught,

of course the amount of memory is higher. Corona doesn’t wait till that transition.to if finished. So it prints then the memory that has the active newText object. It gets deleted almost 3 seconds after your script finished. Then the garbage collector didn’t punch in. You need to call it if you want to see the result right away. Plus your syntax for the onComplete listener was wrong:

Here is an example:

[lua]local ondelete = function(target)
print(“newText removed”)
local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)

target:removeSelf()
collectgarbage(“collect”)

local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)
end

local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)

– show score
local msg = display.newText( “99999”, 0, 0, nil, 14 )

msg:setTextColor( 200, 200, 200, 255 )
msg:translate(100, 160 )
transition.to( msg, {time = 500, alpha=0.6, onComplete = ondelete } )
–transition.to( msg, {time = 500, alpha=0.5, onComplete = function(target) target:removeSelf(); print(“newText removed”); print (“mem=”…system.getInfo(“textureMemoryUsed”));end } )

local mem = system.getInfo(“textureMemoryUsed”)
print ("Texture memory = " … mem)
print (“Script finished”)
[/lua]

[import]uid: 5712 topic_id: 2724 reply_id: 8139[/import]