6

我的理解是,一個類的基本數據類型(UINT,字符串,數字等)不需要被設置爲null垃圾收集。ActionScript - 內存管理的基元/非基元對象之間的區別?

例如,我不要求寫在下面的類此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; 
     } 
    } 
} 

如果這是真的,我相信這是,什麼是原始類型和對象的對象之間的差異關於內存分配的非原始類型?

回答

6

據我所知,GC邏輯的flash播放器VM最完整,最詳細的解釋位於in the blog of Alex Harui, written back in 2007。直接鏈接:GCAtomic.ppt

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

GC邏輯涉及的引用和參考計數。而且由於您無法獲得對ActionScript中原語的引用,因此在這方面您無法對GC進行任何操作。

編輯只記得格蘭特斯金納的另一nice set of articles on GC and resource management

+0

GCAtomic.ppt的鏈接已被打破,但它看起來像有人通過Slideshare提供:http://www.slideshare.net/bufanliu/gc-atomic –

1

GC刪除沒有被任何對象強引用的對象。原始類型字段根本不被引用 - 它們的值直接存儲在包含對象的內存中(至少我認爲是這樣)。

我希望它有幫助。