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

夙愿已清 提交于 2020-01-27 20:59:27

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6570105/actionscript-difference-between-primitive-non-primitive-objects-for-memory-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!