Continuous display object animation eats all memory

Hello,

I have a group of display objects that I want to animate contiuously “in the background” while the rest of the game is running. Below is an example of an animation. As you can see, there are a sequence of transitions that end up with a recursive call to the same method to continue the animation. There are also other animations with more complex animation patterns. The problem is that after a few seconds of execution, the memory usage shoots through the roof and the whole thing just freezes…

I have tried to put it in a runtime event listener, but since the animations consist of a sequence of transitions and delays, I could not get it to work.

The question is: what is the proper way to iterate continuously over an animation sequence?

[lua]

function pulsateObject()
    if(pulsateGroup ~= nil)then
        for i=1, #pulsateGroup do
                transition.to(pulsateGroup[i], {time = 700, xScale=0.9, yScale=0.9, onComplete=function()
                        transition.to(pulsateGroup[i], {time = 700, xScale=1.0, yScale=1.0, onComplete =  function ()
                            pulsateObject()
                    end})
            end})
        end
    end
end

[/lua]

Thanks in advance for your help!

Lets say you have 3 objects in the group and call pulsateObject().

Now you loop through the 3 objects and pulsate them all at the same time. Everything is fine.

At the end of the pulsations you call pulsateObject again 3 times for all 3 objects and each of those 3 times will loop through the 3 objects in the group again. So you have now started 3x3 = 9 pulsations (for 3 objects). On third loop you will have started 9x3 = 21 pulsations etc. 

Hope that made sense.

It makes absolute sense, you are right of course… Thanks!

Lets say you have 3 objects in the group and call pulsateObject().

Now you loop through the 3 objects and pulsate them all at the same time. Everything is fine.

At the end of the pulsations you call pulsateObject again 3 times for all 3 objects and each of those 3 times will loop through the 3 objects in the group again. So you have now started 3x3 = 9 pulsations (for 3 objects). On third loop you will have started 9x3 = 21 pulsations etc. 

Hope that made sense.

It makes absolute sense, you are right of course… Thanks!