What is inside Corona stageObject?

Hello fellow Corona devs,

Today I was trying to uncover some minor leaks in my app, and decided to inspect every children of the stageObject (display.getCurrentStage()) to found out what wasn’t in the right place (using the “oh so good” properties _defined & _lastChange).

What I noticed though is that even in a blank composer scene, the stageObject comes with at least 2 children whose function and identity is pretty much unknown… they don’t even have _defined and _lastChange properties  assigned (both are nil)

Here’s a sample code that highlights this behaviour:

main.lua

local composer = require ("composer") inspect = require("Libs.inspect") local options = {effect="fade", time=500 } composer.gotoScene("test", {effect="fade", time=1000})

test.lua

local composer = require("composer") local scene = composer.newScene() function scene:create(event) local sceneGroup = self.view self.view.name = "------------- SCENE ONE" local stage = display.getCurrentStage() print("CURRENT TOTAL STAGE CHILDREN",stage.numChildren) for i = 1, stage.numChildren do print(i,stage[i].numChildren) if stage[i].numChildren then if stage[i].numChildren \> 0 then for k = 1, stage[i].numChildren do if stage[i][k].\_defined then print("STAGE SON WITH CHILDREN",stage[i][k].\_defined, stage[i][k].\_lastChange) else print(""NOT DEFINED SON WITH CHILDREN",stage[i][k].\_defined, stage[i][k].\_lastChange) end end else print(inspect(stage[i])) end else if stage[i].\_defined then print("STAGE SON WITHOUT CHILDREN",stage[i].\_defined, stage[i].\_lastChange) else print("NOT DEFINED STAGE SON WITHOUT CHILDREN",inspect(stage[i])) end end end end --[removed other composer events from the sample, since they are left untouched in this code]

And here is my console output:

CURRENT TOTAL STAGE CHILDREN 3 1 0 SON WITH 0 CHILDREN { \_class = \<1\>{ \_\_index = \<table 1\>, addEventListener = \<function 1\>, removeEventListener = \<function 2\>, \<metatable\> = \<2\>{ \_\_index = \<table 2\>, \_indexForType = { function = "\_functionListeners", table = "\_tableListeners" }, \_super = \<3\>{ \_\_index = \<table 3\>, new = \<function 3\>, newClass = \<function 4\> }, addEventListener = \<function 5\>, didRemoveListener = \<function 6\>, dispatchEvent = \<function 7\>, dummyFunction = \<function 8\>, dummyTable = {}, getOrCreateTable = \<function 9\>, removeEventListener = \<function 10\>, respondsToEvent = \<function 11\>, \<metatable\> = \<table 3\> } }, \_proxy = \<userdata 1\>, \<metatable\> = { \_\_index = \<function 12\>, \_\_newindex = \<function 13\> } } 2 nil NOT DEFINED SON WITHOUT CHILDREN { \_class = \<1\>{ \_\_index = \<table 1\>, addEventListener = \<function 1\>, removeEventListener = \<function 2\>, \<metatable\> = \<2\>{ \_\_index = \<table 2\>, \_indexForType = { function = "\_functionListeners", table = "\_tableListeners" }, \_super = \<3\>{ \_\_index = \<table 3\>, new = \<function 3\>, newClass = \<function 4\> }, addEventListener = \<function 5\>, didRemoveListener = \<function 6\>, dispatchEvent = \<function 7\>, dummyFunction = \<function 8\>, dummyTable = {}, getOrCreateTable = \<function 9\>, removeEventListener = \<function 10\>, respondsToEvent = \<function 11\>, \<metatable\> = \<table 3\> } }, \_functionListeners = { tap = { \<function 12\> }, touch = { \<function 13\> } }, \_proxy = \<userdata 1\>, \<metatable\> = { \_\_index = \<function 14\>, \_\_newindex = \<function 15\> } } 3 0 SON WITH 0 CHILDREN { \_class = \<1\>{ \_\_index = \<table 1\>, addEventListener = \<function 1\>, removeEventListener = \<function 2\>, \<metatable\> = \<2\>{ \_\_index = \<table 2\>, \_indexForType = { function = "\_functionListeners", table = "\_tableListeners" }, \_super = \<3\>{ \_\_index = \<table 3\>, new = \<function 3\>, newClass = \<function 4\> }, addEventListener = \<function 5\>, didRemoveListener = \<function 6\>, dispatchEvent = \<function 7\>, dummyFunction = \<function 8\>, dummyTable = {}, getOrCreateTable = \<function 9\>, removeEventListener = \<function 10\>, respondsToEvent = \<function 11\>, \<metatable\> = \<table 3\> } }, \_proxy = \<userdata 1\>, name = "------------- SCENE ONE", \<metatable\> = { \_\_index = \<function 12\>, \_\_newindex = \<function 13\> } }

So, here you can see that the last children of the stageObject is the “test” scene wich I am creating… but I have no clue about the first two children.

Based on my modest knowledge of Corona, I would assume that the first Children is the main View of the project (practically the view associated with the stage object).

The second children has some touch and tap listeners, so I would assume that there is a “big father” touch listener that is always active in the background of my app??

This are just assumptions though, has someone got any insights about this? 

Moreover, when “scanning through” the stage children to obtain every displayObject currently active on my app, should I start from the third element inside the stage table, since the first two children seems to be automatically created when launching the app, and I expect them to be fixed at indexes 1 and 2 (like stage[1] and stage[2] always pointing to those first two children created!

Hope to have an answer and keep up the good work! ^^