Lua tables vs Corona display groups

Hi all,

 
I have a question about Corona Display Groups versus normal lua tables.

 
The case is we are creating an object and inserting it into a table. (versus creating and image and inserting it to a Display Group)

 
 
 

-- In lua: myVariable = "My String Is here" -- x kb memory used myTable = {} table.insert(myTable, myVariable) -- 2x kb memory used AND myVariable and myTable[1] are different variables -- In Corona myImage = display.newImage( "image.png") -- (1) -- x kb texture memory used myDisplayGroup = display.newGroup() -- myDisplayGroup:insert(myImage) -- still x kb texture memory used -- myDisplayGroup[1] and myImage are the same thing (but in lua they differ) what happened to first myImage variable definition @1, how did they come together?  

 

 
I think there is some differences between lua tables and corona display groups’ tables.

 
Any comments about this situation?

 
Thank You.

I don’t fully understand how strings are managed in Lua.  They don’t act like allocated memory.  I’m purely speculating, but the speculation fits the observation.

str = “some string”

strtable = {}

strtable[1] = str

In this case, str and strtable[1] are different variables each holding a string “some string”.  Basically it copied the data for the string.  In the 2nd case:

img = display.newImageRect()

img is a small table containing a bunch of 4 byte “pointers” to the various allocated memory and functions and that table is represented by a 4 byte number which is a pointer to the table.  When you insert it into the display group (which is really just a big table with some pointers to helper functions), all you are doing is allocating a new 4 bytes to hold the pointer.  Such small numbers probably don’t show up if you’re dealing with kbytes (1024 bytes per kbyte) of data.  Strings are probably large enough to show up.

I don’t fully understand how strings are managed in Lua.  They don’t act like allocated memory.  I’m purely speculating, but the speculation fits the observation.

str = “some string”

strtable = {}

strtable[1] = str

In this case, str and strtable[1] are different variables each holding a string “some string”.  Basically it copied the data for the string.  In the 2nd case:

img = display.newImageRect()

img is a small table containing a bunch of 4 byte “pointers” to the various allocated memory and functions and that table is represented by a 4 byte number which is a pointer to the table.  When you insert it into the display group (which is really just a big table with some pointers to helper functions), all you are doing is allocating a new 4 bytes to hold the pointer.  Such small numbers probably don’t show up if you’re dealing with kbytes (1024 bytes per kbyte) of data.  Strings are probably large enough to show up.