1.a sprite,has no parent, is any function(method) can keep it not destroyed?
2.a sprite,it parent is stage ,when "stage:removeChild(sprite)" , is any function(method) can destroy it frome memory?
3.a sprites has no parent,how long destroy from memory? and what is the process?
Now I will try to answer your questions
1- when your sprite has no parent (not added to stage) then it is not displayed on the screen but is kept in memory
2- when you do stage:removeChild(sprite) lua and its garbage collector will at some point automatically remove it from memory, to be sure you can set sprite = nil
3- same as above
Note if you want to hide (not destroy) your sprite you can call sprite:setVisible(false), ...
Destroy from memory is called garbageCollector. From the wiki:
There are quite a few posts on the forum like these ones:
giderians, please correct me if I am wrong
emm, Where is the problem?
local container = Sprite.new()
local ball1 = Bitmap.new(Texture.new("ball.png", true))
local ball2 = Bitmap.new(Texture.new("ball.png", true))
stage:addChild(container) -- add
stage:removeChild(container) -- remove
local timer = Timer.new(20000, 1)
stage:addChild(container) --- why still can addchild?
so I guess you want to destroy container from memory?
you need to set it to nil before collectgarbage.
so I guess you want to destroy container from memory? --- yes you are right
1.if not set it to "nil",it will never be destroyed? even though it is local variable?
2.if "container" has not parent and not set "nil", even though auto-collect garbage or manual 'collectgarbage()' ,it still exist?
2- yes it still exists because "gideros" thinks that you will use this object later in your game/app so it doesn't destroy it for you.
So, to be freeable, an object must not be reachable through any reference, either those you set yourself in lua (a global, a local, an upvalue, a parameter of a still running function, etc), or those Gideros keeps under the hood (Sprites attached to the stage, a running MovieClip, etc).
Likes: MoKaLux, SinisterSoft