Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript - Difference Between Primitive / Non-Primitive Objects for Memory Management?

my understanding is that primitive types (uint, string, Number, etc.) of a class do not need to be set to null for garbage collection.

for example, i am not required to write this dispose() method in the following class:

package
{
//Imports
import flash.display.Shape;

//Class
public class DrawSquare extends Shape
    {
    //Properties
    private var squareColorProperty:uint;

    //Constructor
    public function DrawSquare(squareColor:uint)
        {
        squareColorProperty = squareColor;

        init();
        }

    //Initialize
    private function init():void
        {
        graphics.beginFill(shapeColorProperty);
        graphics.drawRect(0, 0, 200, 200);
        graphics.endFill();
        }

    //Dispose
    public function dispose():void
        {
        squareColorProperty = null;
        }

    //Get Shape Color
    public function get squareColor():uint;
        {
        return squareColorProperty;
        }
    }
}

if this is true, which i believe it is, what is the difference between objects of primitive types and objects of non primitive types concerning memory allocation?

like image 429
Chunky Chunk Avatar asked Jul 04 '11 10:07

Chunky Chunk


1 Answers

As far as I know, the most complete and detailed explanation of GC logics in flash player VM is located in the blog of Alex Harui, written back in 2007. Direct link: GCAtomic.ppt.

And here are some useful hints on GC from Grant Skinner.

GC logic deals with references and reference counting. And since you can not obtain a reference to a primitive in ActionScript, you can do nothing about GC in this aspect.

EDIT Just remembered another nice set of articles on GC and resource management by Grant Skinner.

like image 173
Michael Antipin Avatar answered Nov 15 '22 07:11

Michael Antipin