memory management,

Hi, I have an array of clouds that I move using a transition. When I go out of screen, I use the for loop to remove the objects. Do I need to stop any transitions that are still running or will display.remove( obj ) auto remove any transitions that haven’t finished?

Thanks,

Mark

– clean up
local function killObj(obj)
    display.remove( obj )
    obj = nil
end

  for i=#clouds, 0, -1 do      
    killObj(clouds[i])
  end

Anyone any thoughts on this?

Thanks,

Mark

Hi Mark,

If you haven’t assigned the transition to anything, i.e., if you just wrote “transition.to(…)” instead of “someVar = transition.to(…)”, then you should be fine.  If you do assign it to a variable, and that variable is not attached to (not a property of) the object being transitioned, then you’ll have to remove it yourself by nil’ing that variable when the transition is complete.

  • Andrew

Thanks Andrew, thats interesting. I’m a beginner with Corona and have a lot to learn!

My function looks like this. Is there any fundamental problems with this?

Thanks,

Mark

local function drawLevel()

– clear clouds from ‘prev screen’’
  for i=#clouds, 0, -1 do      
    killObj(clouds[i])
  end

 
numOfClouds =  mRandom(4,9) – define how many clouds on screen
for i=0, numOfClouds do
    
    local alphaRandom =  mRandom(1, 3)
    local flipXRandom =   mRandom(10)
    local stretchXRandom =   mRandom(10)
    local stretchXamtRandom =   mRandom(2, 4)
    local windspeed = mRandom(10000, 40000)
    
    clouds[i]  = display.newImage(“images/cloud3.png”)
 
    if flipXRandom >6 then clouds[i].xScale = -1 end
    if stretchXRandom >6 then clouds[i].xScale = stretchXamtRandom end
   
    clouds[i].alpha = “0.” … alphaRandom
    clouds[i].x= screenLeft+mRandom(screenWidth)
    clouds[i].y= screenTop+mRandom(40,screenHeight)
    
    transition.to( clouds[i], {delay=0, time=windspeed, x=screenLeft })
    
    group:insert(clouds[i])     
   
 end

At a very quick glance, it looks OK to me in terms of memory management.

  • Andrew

Thanks Andrew, I’m sure there’s plenty of things I’ll get wrong as I move forward with this - just hoping to minimise the problems! Thanks for looking.

Mark

Anyone any thoughts on this?

Thanks,

Mark

Hi Mark,

If you haven’t assigned the transition to anything, i.e., if you just wrote “transition.to(…)” instead of “someVar = transition.to(…)”, then you should be fine.  If you do assign it to a variable, and that variable is not attached to (not a property of) the object being transitioned, then you’ll have to remove it yourself by nil’ing that variable when the transition is complete.

  • Andrew

Thanks Andrew, thats interesting. I’m a beginner with Corona and have a lot to learn!

My function looks like this. Is there any fundamental problems with this?

Thanks,

Mark

local function drawLevel()

– clear clouds from ‘prev screen’’
  for i=#clouds, 0, -1 do      
    killObj(clouds[i])
  end

 
numOfClouds =  mRandom(4,9) – define how many clouds on screen
for i=0, numOfClouds do
    
    local alphaRandom =  mRandom(1, 3)
    local flipXRandom =   mRandom(10)
    local stretchXRandom =   mRandom(10)
    local stretchXamtRandom =   mRandom(2, 4)
    local windspeed = mRandom(10000, 40000)
    
    clouds[i]  = display.newImage(“images/cloud3.png”)
 
    if flipXRandom >6 then clouds[i].xScale = -1 end
    if stretchXRandom >6 then clouds[i].xScale = stretchXamtRandom end
   
    clouds[i].alpha = “0.” … alphaRandom
    clouds[i].x= screenLeft+mRandom(screenWidth)
    clouds[i].y= screenTop+mRandom(40,screenHeight)
    
    transition.to( clouds[i], {delay=0, time=windspeed, x=screenLeft })
    
    group:insert(clouds[i])     
   
 end

At a very quick glance, it looks OK to me in terms of memory management.

  • Andrew

Thanks Andrew, I’m sure there’s plenty of things I’ll get wrong as I move forward with this - just hoping to minimise the problems! Thanks for looking.

Mark