hi,
I wrote a function which I thought I had eliminated all the memory leaks in.
But when I test the garbagecollect(“count”), I see a bit a of a memory leak going on…
the function adds a physics object to the screen, and checks to see if the player has managed to hit it.
I’m posting only part of the code for it because it’s too long, but this part has the cleanup in it so I think that’s where the problem is.
Can someone take a look at the code and see if i’ve missed something please?
local function suck(obj)
local good=display.newImage(“Photos/good.png”)
good.x=obj.x; good.y=obj.y
ball.ballX(obj)
local trans2=transition.to(good, {time=100, xScale=2,yScale=2})
local trans=transition.to(obj, {time=250, width=0,height=0,x=obj.x, y=obj.y,alpha=0})
timer.performWithDelay(300,function()
if isPlaying then
trans=nil;good:removeSelf(); good=nil;trans2=nil
end
end)
end
local function loop(event)
for i = #t, 1, -1 do
local object = t[i]
if(object~=nil) then
if(isPaused) then
object.isVisible=false
else
object.isVisible=true
end
if(object.y~=nil) and object.y>700 then
score.setScore(-20)
local child = table.remove(t, i)
if child ~= nil then
child:removeSelf()
child = nil
check=nil
isPopped=nil
px=nil;pl=nil;rotate=nil
suck=nil
reventar=nil
crate=nil
Runtime:removeEventListener(“enterFrame”, loop)
Runtime:removeEventListener(“collision”,reventar)
loop=nil
end
elseif(object.fastkill) then
score.setScore(100)
isPopped=isPopped+1
timer.performWithDelay(isPopped*50,function()
local popSound = audio.play( pop )
isPopped=0
end)
ball.addOne()
local popSound = audio.play( pop )
suck(object)
local child = table.remove(t, i)
local timeCrate=timer.performWithDelay(300,function()
if child ~= nil and isPlaying then
child:removeSelf()
child = nil
check=nil
ballAdd=nil
isPopped=nil
isPopped=nil
suck=nil
reventar=nil
crate=nil
px=nil;pl=nil;rotate=nil
Runtime:removeEventListener(“enterFrame”, loop)
Runtime:removeEventListener(“collision”,reventar) loop=nil
timeCrate=nil
end
end)
end
end
end
end
for i=1,#t do
t[i].id = i
end
Runtime:addEventListener(“enterFrame”, loop)
Runtime:addEventListener(“collision”,reventar)

