Memory usage and garbage collection of objects in AS3

I want to know about type Object, especially when it comes to garbage collection in Flash.

I know that the items will be ready for garbage collection in such situations:

// create
var ar:Array = [];

var mc:MovieClip = new MovieClip();
mc.addEventLisntener(blah, blah);

ar.push(mc);
addChild(mc);

// kill & gc
ar.splice(0, 1);
mc.removeEventListener(blah, blah);
removeChild(mc);

But how / will Objectreceive garbage collected in situations like below.

Let's say that I have a function in my class MartysMCthat I parse Objectthrough:

package
{
    import flash.display.MovieClip;

    public class MartysMC extends MovieClip
    {
        /**
         * Updates this
         * @param obj An object containing key/value pairs to represent new property values
         */
        public function update(obj:Object):void
        {
            var i:String;
            for(i in obj)
            {
                this[i] = obj[i];
            }
        }
    }
}

And now I use this function as follows:

var mmc:MartysMC = new MartysMC();

var dataObject:Object =
{
    x: 10,
    y: 34,
    alpha: 0.6
};

mmc.update(dataObject);

What is going on with dataObject? Will it collect trash from here? Even what about the object on this line:

mmc.update({x:15,y:18,name:"marty"});
+5
source share
2 answers

, GC, Dictionary , true, , cheeck :

var d:Dictionary = new Dictionary(true)
d[myObject] = whatever

, .

, wonderfl: http://wonderfl.net/c/e9W4

, .

+3

, , , GC. ( GC pass , .) , , (obj[i]) - ( .)

+2

All Articles