> 2. You say my version will “likely crash” … NO, it does not crash!
I misread your post.
> c.parent:remove© … is identical to c:removeSelf()
Yes.
> But that will not change the fact that removeSelf() is not documented anywhere in your documentation and is just mentioned once in the Game Edition SDK.
Please file a bug: http://developer.anscamobile.com/content/bug-submission
> In addition… his “c” is not getting freed… the local scope of main.lua is not freed till the program ends …
In GC environments, you must be careful about timing assumptions.
In Corona, the GC system is tiered so that the Lua GC can trigger additional resource cleanup, e.g. graphics resources. However, that add’l cleanup doesn’t happen at the same time as the initial Lua GC; it happens sometime later. Also, Lua’s incremental GC doesn’t immediately cleanup variables, so hitting the end of the main.lua chunk does not imply that local variables get GC’d right away. For a lot of programmers used to non-GC environments (e.g. automatics in C++), the latter can be confusing.
These recent examples do not trigger screen updates. Therefore, Corona doesn’t do the add’l cleanup.
For example, here’s a modified HelloWorld example which is similar to Fogview’s
local background = display.newImage( "world.png" )
background:removeSelf()
myText = display.newText( "Hello, World!", 10, 80, "MarkerFelt-Thin", 60 )
myText:setTextColor( 255,180,90 )
In this example, Lua eventually GC’s the local “background” variable (as there are no more references to it), but it takes awhile since Lua’s GC is incremental. During screen updates, Corona periodically looks for display objects that need to be cleaned up. However, in the above example, the screen is never updated. Therefore, Corona doesn’t perform the clean up.
Here’s a modified version that triggers screen updated by changing the alpha of the text every frame:
local background = display.newImage( “world.png” )
background:removeSelf()
myText = display.newText( "Hello, World!", 10, 80, "MarkerFelt-Thin", 60 )
myText:setTextColor( 255,180,90 )
local function foo(event)
myText.alpha = math.random( 255 ) / 255
end
Runtime:addEventListener( "enterFrame", foo )
In this case, sometime *after* Lua GC’s “background”, Corona will free the underlying display object and release references to graphics resources it is using. Keep in mind, Corona does not immediately free display objects at the same time the corresponding Lua portion is GC’d.
> Correct my OP code and / or file this as bug and correct the SDK!
If you have support issues, please use the “Developer Support” forum.
[import]uid: 26 topic_id: 1251 reply_id: 3492[/import]
