Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Can I have details about memory management? — Gideros Forum

Can I have details about memory management?

edited August 2013 in General questions
How I destroy stuff? Just doing a "nil" on them is enough?


What happen if I do this?

local group;
do
local someText = TextField.new(...);
group:AddChild(someText);
stage:AddChild(group);
end

my theories: one, is that someText is retained until you delete group, the other, is that as soon someText is out of scope it gets deleted, and disappears from group. So, what one is it?
I make games for children: http://www.kidoteca.com

Comments

  • So, if I undertstood, on my case, the result would be that the "someText" remains working correctly, and to delete it I need to:

    remove it from group...

    OR

    remove group from stage AND set group to nil.

    Is that correct?
    I make games for children: http://www.kidoteca.com
  • yes removing from the group
    yes remove group from the stage
    but setting group to nil depends on the scope, if it goes outside the scope (for example it is in function), then you don't have to nil it ;)

  • Ok, thanks :)

    And that example my intention is that group is local to the chunk. I don't think chunks ever go out of scope in gideros if they run on start or are called with "require", are they?
    I make games for children: http://www.kidoteca.com
  • their scope is usually the whole file and most probably you are right, it remains in memory all the time ;)
  • john26john26 Maintainer
    One easy way to think about it is to ask yourself, "is there any way I can access this object". If the answer is no then the object will be garbage collected.

    So...
    foo=Bitmap.new(Texture.new("foo.png"))
    stage:addChild(foo)
    foo=nil
    I've now nilled out the object but can I still access it? Yes, through stage:getChildAt(1). So the object will not be garbage collected, Gideros is maintaining a link to it.

    What about this
    foo=Bitmap.new(Texture.new("foo.png"))
    bar=Bitmap.new(Texture.new("bar.png"))
     
    stage:addChild(foo)
    foo:addChild(bar)
    foo=nil
    foo:removeFromParent()
    I can access bar from foo using foo:getChildAt(1), but I can't access foo at all so there is really no way to access foo or bar: both are garbage collected.
Sign In or Register to comment.