Memory Cleanup

Hi dyson,

I am having a memory cleanup issue.  When a game is over, and a user wants to play again, I regenerate the scenario, first removing all sprites and then re-adding them.  MTE gets laggier every time they do a Play Again until my game finally dies. 

This is what I am doing for cleaup:

    asprite = mte.getSprites()
    if asprite == nil then do return end end
            
        for i = 1,#asprite do
            if asprite[i] ~=nil  then
                  mte.removeSprite(asprite[i], true)
            end        
        end

    

       for i = 1, #enemy do
            if enemy[i] ~=nil and enemy[i].isdead ~= true then enemy[i]:removeSelf() end
        end

    enemy = nil
    enemy={}

Is there something I should be doing to clean out my sprites and re-adding them?   (I don’t want to unload my tile map because It is just a single level map that acts like a background canvas.

Thanks, Greg

>> In my game on each time exit, i am cleaning up mte by calling mte.cleanup(). But still my memory is keep on increasing for each game i play . More over i am manually cleaning all the objects which i am creating . 

Thanks,

Kumar KS.

Hi Dyson,

I’m having a few problems with v990:

The mte.getsprites now returning nil was a pain but I dealt with it.   I noticed a big increase in lag and also my collision detection started messing up when a sprite is close to the edge of the map.   I will post more info when I am finished testing.

Did you ever find any problems with memory cleanup when removing sprites?  (If so I’d like to retrofit v984 with the fix)

Thanks again, Greg

I am having problems with the removeSprite function in general, I don’t think its removing stuff properly or maybe I’m just doing it 100% wrong.

Is how I remove an object:

local function cleanNet(event)
    physics.removeBody(event)
    event:removeSelf() – i just started using this, but if i take it out doesn’t seem to change anything
    mte.removeSprite(event, false) – can’t use true or crash
    event.isVisible = false --needed because doesn’t seem to be niling
    event = nil
    return true
end

 

I would like to know how to exactly remove a sprite properly, because there is too many problems going on when they aren’t being removed properly. Also when I do just normal remove sprite’s since I can’t use the true part of the function I am stuck with false, the leftover of the sprite is now stuck on corona sdk display so I have to do object.isVisible = false to hide everything…

How are you calling that function?

I call the function just passing the variable in like:

cleanNet(spiderNet) and using the above function to clean it.

More specifically I call it in a onCollision event

EDIT: bad code, fix is edit below

I’ve also done it with a timer in different cases, doesn’t seem to change anything:

Gremlin do you think this is a bug? or am I doing the remove process 100% wrong?

EDIT: I ended up solving it thanks! I was being dumb and forgot about the scope rules noob mistake! I needed to return the event in the function and do item.pot_1 = removeItem(item.pot_1); etc.

I no longer have remoreSprite problems anymore!!

Hi Dyson,

I’m having a few problems with v990:

The mte.getsprites now returning nil was a pain but I dealt with it.   I noticed a big increase in lag and also my collision detection started messing up when a sprite is close to the edge of the map.   I will post more info when I am finished testing.

Did you ever find any problems with memory cleanup when removing sprites?  (If so I’d like to retrofit v984 with the fix)

Thanks again, Greg

I am having problems with the removeSprite function in general, I don’t think its removing stuff properly or maybe I’m just doing it 100% wrong.

Is how I remove an object:

local function cleanNet(event)
    physics.removeBody(event)
    event:removeSelf() – i just started using this, but if i take it out doesn’t seem to change anything
    mte.removeSprite(event, false) – can’t use true or crash
    event.isVisible = false --needed because doesn’t seem to be niling
    event = nil
    return true
end

 

I would like to know how to exactly remove a sprite properly, because there is too many problems going on when they aren’t being removed properly. Also when I do just normal remove sprite’s since I can’t use the true part of the function I am stuck with false, the leftover of the sprite is now stuck on corona sdk display so I have to do object.isVisible = false to hide everything…

How are you calling that function?

I call the function just passing the variable in like:

cleanNet(spiderNet) and using the above function to clean it.

More specifically I call it in a onCollision event

EDIT: bad code, fix is edit below

I’ve also done it with a timer in different cases, doesn’t seem to change anything:

Gremlin do you think this is a bug? or am I doing the remove process 100% wrong?

EDIT: I ended up solving it thanks! I was being dumb and forgot about the scope rules noob mistake! I needed to return the event in the function and do item.pot_1 = removeItem(item.pot_1); etc.

I no longer have remoreSprite problems anymore!!