I’m trying to understand what happens to local variables when they go out of scope after having been displayed. Consider this Lua code:
[lua]
local function localAddCircle()
local circle = display.newCircle(200,200,10)
print (type(circle)) – prints “table”
end
localAddCircle()
print (type(circle)) – prints nil
print (#display) – prints 0
[/lua]
Since circle is a local variable, it’s not accessible outside of the function. I assume it’s garbage collected. I understand this part.
I don’t understand the relationship between the local circle variable and the display table. As you can see, the length of the display table is 0. It’s empty, yet the circle remains displayed on the screen.
What’s going on under the covers here?