ActionScript - 原始对象和非原始对象在内存管理方面的区别是什么?

6

我的理解是,类的基本类型(如uint、string、Number等)不需要设置为null以进行垃圾回收。

例如,在以下类中,我不需要编写此dispose()方法:

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;
        }
    }
}

如果这是真的,我相信是这样的,原始类型的对象和非原始类型的对象在内存分配方面有什么区别?
2个回答

6

GCAtomic.ppt的链接已经失效,但是看起来有人通过Slideshare提供了它:http://www.slideshare.net/bufanliu/gc-atomic - pm_labs

1

GC(垃圾回收器)会移除任何没有被其他对象强引用的对象。原始类型的字段根本不被引用 - 它们的值直接存储在包含对象的内存中(至少我是这么认为的)。

希望能对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接