Problems with memory and animations

Hi guys,

I’m having problems at a stage of my match 3 game. In the main class must eliminate the element of a table and carry out checks on the same table. For this reason I eliminate completely the item from the table (this element is a “candy” object). I would like to see an explosion effect to 'elimination of candy. as I said the class “Candy” is deleted immediately to perform controls so it can not be the effect. I was thinking of creating a module to be called to 'elimination of candy. This module would show only the burst effect.

However, I am finding memory leaks can help to plug the leaks?

if there are better ways to my logic let me know! enclose the code with memory loss.

Thanks and sorry for my bad English :slight_smile:

Candy class-------

local Candy = {} Candy.\_\_index = Candy function Candy.new(clr, dimCandy) local instance = { color = clr, image = display.newImageRect("images/candy/"..clr..".png",dimCandy,dimCandy), dL = dimCandy, movable = true, bloccante = "I", matchTestable = true, mark, punti = 20 } setmetatable(instance, Candy) return instance end function Candy:getDepth() return 2 end function Candy:whoIs() return "Candy" end function Candy:destroy() self.image:removeSelf() self.image = nil self.dL = nil self.color = nil self.movable = nil self.bloccante = nil self.matchTestable = nil self.mark = nil self.punti = nil end function Candy:destroyClass () Candy.new = nil Candy.getDepth = nil Candy.whoIs = nil Candy.destroy = nil Candy.destroyClass = nil Candy.\_\_index = nil Candy = nil end return Candy

—module for effect

local extra = {} function extra.prova(posX, posY) local posX = 400 local posY = 900 local dL = 80 local tempo = 1000 local function destroy( self ) transition.cancel(self.tmpLamp) self.tmpLamp:removeSelf() self.tmpLamp = nil transition.cancel(self.circle) self.circle:removeSelf( ) self.circle = nil for i = #self.stars,1,-1 do transition.cancel(self.stars[i]) self.stars[i]:removeSelf( ) self.stars[i] = nil end self.stars = nil self.nStars = nil self = nil destroy = nil end local animazione = {} animazione.stars = {} animazione.nStars = 10 animazione.tmpLamp = display.newImageRect("images/candy.png", dL, dL) animazione.tmpLamp.x = posX animazione.tmpLamp.y = posY transition.to( animazione.tmpLamp, {parms} ) animazione.circle = display.newImageRect("images/circle.png",0,0) animazione.circle.x = posX animazione.circle.y = posY transition.to( animazione.circle, {parms}) for i = 1, animazione.nStars do animazione.stars[i] = display.newImageRect("images/stella.png", dL\*0.20, dL\*0.20) animazione.stars[i].x = posX animazione.stars[i].y = posY transition.to( animazione.stars[i], {parms}) transition.to( animazione.stars[i], {parms}) end animazione.onComplete = destroy transition.to(animazione, {delay = tempo , time = 0, onComplete = animazione}) end return extra

main class

 function foo () for i = 1, 100 do extra.prova(700,700) end end foo()

before cycle = MEMORY= 282.405 KB   | TEXTURE= 0.01031494140625

after             = MEMORY= 376.094 KB   | TEXTURE= 0.01031494140625

First, I’m not sure transition.to supports object’s in their onComplete call.

Secondly I’m not sure you want a transition there any way. This sounds like you should be calling timer.performWithDelay() instead:

timer.performWithDelay( tempo, function() destroy( animazione ); end, 1 )

Thanks Rob,

I tried with your advice but the memory still problems: 

before: MEMORY= 282.554 KB | TEXTURE= 0.01031494140625

after:    MEMORY= 378.203 KB | TEXTURE= 0.01031494140625

Also I was wondering if you create a function within timer was right. I already tried for cases where I’m forced to pass parameters but I was wondering if it was the best solution.

Finally I wanted to ask if the idea of using a module only for the animation was good. :huh:

thank you again :slight_smile:

First of all, an increase of 96 kilobytes is pretty trivial.  A single background image could be 10’s of megabytes or 10,000’s of kilobytes. To put all of this in perspective you’re using

378,203 bytes of memory (Lua tables, strings and values). Your device has hundreds of millions of bytes available for your app to use. But you don’t want this number to keep going up and up. Its natural for it to increase as you do more, what you’re looking for is those numbers changing over time. After 10 minutes of play is the number bigger? 

Rob

I did a test playing 10 minutes. At the beginning the memory is:
Main Memory: 0.74 MB Texture mem28.6 MB.
After changing all the scenes of the game:
Main Memory: 0.97 MB Texture mem28.6 MB.
And finally after 10 minutes
Main Memory: 2.09 MB Texture mem30.5 MB.
Also it is known a decrease from 30 to 23 FPS.

A part of my game necessarily requires the use of 3 SnapshotObject. These three snap require a invalidate call with a runtime event listener (enterFrame) . This can increase memory in inserting and removing the objects in SnapshotObject.group?  I use them because 2.5D effects are available to snapshot objects and not in the groups.

I’m worried about this memory-consuming and especially for the reduction of the FPS. Thanks Rob.

First, I’m not sure transition.to supports object’s in their onComplete call.

Secondly I’m not sure you want a transition there any way. This sounds like you should be calling timer.performWithDelay() instead:

timer.performWithDelay( tempo, function() destroy( animazione ); end, 1 )

Thanks Rob,

I tried with your advice but the memory still problems: 

before: MEMORY= 282.554 KB | TEXTURE= 0.01031494140625

after:    MEMORY= 378.203 KB | TEXTURE= 0.01031494140625

Also I was wondering if you create a function within timer was right. I already tried for cases where I’m forced to pass parameters but I was wondering if it was the best solution.

Finally I wanted to ask if the idea of using a module only for the animation was good. :huh:

thank you again :slight_smile:

First of all, an increase of 96 kilobytes is pretty trivial.  A single background image could be 10’s of megabytes or 10,000’s of kilobytes. To put all of this in perspective you’re using

378,203 bytes of memory (Lua tables, strings and values). Your device has hundreds of millions of bytes available for your app to use. But you don’t want this number to keep going up and up. Its natural for it to increase as you do more, what you’re looking for is those numbers changing over time. After 10 minutes of play is the number bigger? 

Rob

I did a test playing 10 minutes. At the beginning the memory is:
Main Memory: 0.74 MB Texture mem28.6 MB.
After changing all the scenes of the game:
Main Memory: 0.97 MB Texture mem28.6 MB.
And finally after 10 minutes
Main Memory: 2.09 MB Texture mem30.5 MB.
Also it is known a decrease from 30 to 23 FPS.

A part of my game necessarily requires the use of 3 SnapshotObject. These three snap require a invalidate call with a runtime event listener (enterFrame) . This can increase memory in inserting and removing the objects in SnapshotObject.group?  I use them because 2.5D effects are available to snapshot objects and not in the groups.

I’m worried about this memory-consuming and especially for the reduction of the FPS. Thanks Rob.