Garbage collection problem

I’m having a garbage collection problem and I know exactly where it’s at: the function checkThreshold() has a reference to the object that I can’t seem to clear or indirectly address so that the object (here, a balloon) is completely removed (verified by the texture memory printing code).

[blockcode]
_W = display.contentWidth;
_H = display.contentHeight;

local physics = require(“physics”);
physics.start();

local balloon = display.newImage(“images/balloon.png”);
balloon.x = _W/2; balloon.y = _H+20;
physics.addBody(balloon, “kinematic”, {density=0, bounce=0, friction=0, radius=40});

function balloon:pop()
if(self.timer) then
timer.cancel(self.timer);
end

self:removeSelf();
self = nil;

–Force garbage collection and check the texture memory to ensure
tmr = timer.performWithDelay(10, function(e)
collectgarbage(“collect”);
timer.cancel(tmr);

print("End Memory Used: " … system.getInfo(“textureMemoryUsed”) * 0.000001);

end, 1);

end

–Check the balloon’s y and destroy the balloon if it passes the threshold
local function checkThreshold(e)
if(balloon.y < 100) then
balloon:pop();
end
end

–Make the balloon rise up
balloon:setLinearVelocity(0,-200);

–Start checking the threshold at regular intervals
balloon.timer = timer.performWithDelay(20, checkThreshold, -1);

–Print the texture memory used at the start
print("Beginning Memory Used: " … system.getInfo(“textureMemoryUsed”) * 0.000001);
[/blockcode]

any help is greatly appreciated!

hdez [import]uid: 7947 topic_id: 8270 reply_id: 308270[/import]