Hi Guys/Gals,
This thought has been in the back of my mind for awhile. It relates to forward declared variables that are used in conjunction with Composer scene management.
Say I have “scene1.lua” and “scene2.lua”, both that use the standard Composer template. Within “scene1.lua” assume I have a couple forward declared variables (above the scene event functions) such as:
local scoreText local score
(Referring to the example https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/)
In the case of “scoreText”… I will later allocate a display.newText() object to it within the scene:create() function… and also add that object to “scene.view” so it can be managed by Composer.
In the case of “score”, it is never allocated “scene.view”.
Say I then transition out of “scene1.lua” and into “scene2.lua”. Within the “scene2.lua”, I call
local prevScene = composer.getSceneName( "previous" ) composer.removeScene( prevScene)
which should dispose of all objects that were managed by “scene.view” within the “scene1.lua” file. I take the wording dispose to mean it both removes that object from the display group and NIL’s out any associated variables for garbage collection (correct me if not the case). Therefore upon removing “scene1.lua” (from within “scene2.lua”) it should automatically handle for me:
display.remove(scoreText) scoreText = nil
However, since the “score” variable lived outside the scene functions (forward declared “file level” variable) and was not specifically inserted into “scene.view” within “scene1.lua”… if I do not explicitly NIL out the “score” variable within the scene:destroy function within “scene1.lua”… once I transition to “scene2.lua” and then call “composer.removeScene(“scene1”)” as mentioned above… does the “score” variable from “scene1.lua” become a (albeit small) memory leak? or does calling “composer.removeScene(“scene1”)” somehow implicitly do this:
score = nil
Thanks in advance!