Removing display objects...

I wonder how to remove image objects from a table like this…

local gfx={image1,image2} image1=display.newImage (...) image2=display.newImage (...) for i=#gfx,1,-1 do      display.remove( ??? ) end  

Is it somehow possible to use a loop to totally destroy the images created in the gfx table?
What can be used at “???” in the code above to manage this?

Thx for your help!

Daniela

Here is some info on loops and how they relate to in-app performance:

http://developer.coronalabs.com/content/performance-and-optimization

Update: Whoops! messed up the link.

I wonder how to remove image objects from a table like this…

local gfx={image1,image2} image1=display.newImage (…) image2=display.newImage (…) for i=#gfx,1,-1 do      display.remove( ??? ) end  

Is it somehow possible to use a loop to totally destroy the images created in the gfx table?
What can be used at “???” in the code above to manage this?

Thx for your help!

Daniela

Hey Daniela, this is quite easy to do, but you have things in an improper order and syntax issues… see the following code:

-- first create the objects so you don't store nil values local image1=display.newImage (...) local image2=display.newImage (...) -- create the table holding your objects local gfx={image1,image2} -- remove the objects for i=1,#gfx do gfx[i]:removeSelf() gfx[i]=nil end

that should do the trick :slight_smile:

Panc software’s link was not working.  Looks like it has an extra space.

Here is the link:

http://developer.coronalabs.com/content/performance-and-optimization

Definitely a good link to know about.  :slight_smile:

Thank you all for your replies and answers. I noticed my sample wasn’t exact enough… so here is a corrected version. I was looking for information on how to remove properly when using a table like this…

local gfx={image1,image2} local myfunction = function()      gfx.image1=display.newImage (...)      gfx.image2=display.newImage (...) end for i=#gfx,1,-1 do      display.remove( ??? ) end  

I tried to remove with “display.remove (gfx[i])”, but of course this is not the right way to do it.

What do I have to use at “???”?

Regarding your sample above eja I have another question:
In your sample you are freeing the stored table images memory, but there is still the variables outside of the table (image1,image2) which also are needed to be removed, isn’t it?
I somehow didn’t get this right regarding removement…

When using an image like this:

local image1=display.newImageRect(...) local image2=display.newImageRect(...) local imgtable={image1,image2}  

What exactly has to be removed to really free all of the memory? Is it enough to free the stuff in the table? I thought that is a reference and I also have to free the image1 and image2? Can someone please help me with this, so I can do this right in the future? :wink:

Thx!

Try:

for k,v in pairs( gfx ) do display.remove ( v ) end gfx = nil

Things can be so easy! :wink: Thank you very much!

Daniela

Here is some info on loops and how they relate to in-app performance:

http://developer.coronalabs.com/content/performance-and-optimization

Update: Whoops! messed up the link.

I wonder how to remove image objects from a table like this…

local gfx={image1,image2} image1=display.newImage (…) image2=display.newImage (…) for i=#gfx,1,-1 do      display.remove( ??? ) end  

Is it somehow possible to use a loop to totally destroy the images created in the gfx table?
What can be used at “???” in the code above to manage this?

Thx for your help!

Daniela

Hey Daniela, this is quite easy to do, but you have things in an improper order and syntax issues… see the following code:

-- first create the objects so you don't store nil values local image1=display.newImage (...) local image2=display.newImage (...) -- create the table holding your objects local gfx={image1,image2} -- remove the objects for i=1,#gfx do gfx[i]:removeSelf() gfx[i]=nil end

that should do the trick :slight_smile:

Panc software’s link was not working.  Looks like it has an extra space.

Here is the link:

http://developer.coronalabs.com/content/performance-and-optimization

Definitely a good link to know about.  :slight_smile:

Thank you all for your replies and answers. I noticed my sample wasn’t exact enough… so here is a corrected version. I was looking for information on how to remove properly when using a table like this…

local gfx={image1,image2} local myfunction = function()      gfx.image1=display.newImage (...)      gfx.image2=display.newImage (...) end for i=#gfx,1,-1 do      display.remove( ??? ) end  

I tried to remove with “display.remove (gfx[i])”, but of course this is not the right way to do it.

What do I have to use at “???”?

Regarding your sample above eja I have another question:
In your sample you are freeing the stored table images memory, but there is still the variables outside of the table (image1,image2) which also are needed to be removed, isn’t it?
I somehow didn’t get this right regarding removement…

When using an image like this:

local image1=display.newImageRect(...) local image2=display.newImageRect(...) local imgtable={image1,image2}  

What exactly has to be removed to really free all of the memory? Is it enough to free the stuff in the table? I thought that is a reference and I also have to free the image1 and image2? Can someone please help me with this, so I can do this right in the future? :wink:

Thx!

Try:

for k,v in pairs( gfx ) do display.remove ( v ) end gfx = nil

Things can be so easy! :wink: Thank you very much!

Daniela