开发者

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

开发者 https://www.devze.com 2023-03-16 22:49 出处:网络
my understanding is that primitive types (uint, string, Number, etc.) of a class do not need to be set to null for garbage collection.

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 funct开发者_JS百科ion 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?


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.


The GC removes objects that are not strong-referenced by any object. Primitive typed fields are not referenced at all - their values are directly stored in the the containing object's memory (at least I think so).

I hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消