We have a function in module 1 - M:animation. Each time it is called, the framerate is slowed and Lua memory increases. After a minute the framerate has reduced from 60 to 1 or 2 frames and Lua memory continues to increase. Changing the Composer scene doesn’t resolve the framerate or return the Lua memory.
After some testing, it seems the leak is compunding each time M:animation is called which (after some testing) might be traced to that part of the function which declares local variables with data associated to the passed in object e.g. local skeleton = self.skeleton
function M:animation (params) local params = params or {} local skeleton = self.skeleton local root = self.root local stateData = self.stateData local state = self.state local name = self.name -- rest of function -- etc end
Later in module 1 are event states such as onStart, onEnd, onComplete. An event is dispatched to a listener in scene1 when the state of the passed in object triggers onComplete.
-- In module 1 state.onComplete = function (trackIndex, loop) --loopCount Runtime:dispatchEvent( {name="animLoop", tag=obj.name} ) end
Then in scene 1, obj:animation is called again from animLoop:
function M:animLoop (event) local event = event local name = event.tag local state = {} obj[name].spine:animation( {onComplete="animLoop", sequence=loop[randPage] }) end end
And the cycle continues like this after each animation completes (in around 3 or 4 second lengths).
The object being created uses Spine to assign special Spine related states and the animation function uses Spine related calls.
I can post more code. Or is this enough to understand how memory might typically compound in an object oriented function like this being continually called?