问题描述
我的理解是类的原始类型(uint、string、Number 等)不需要为垃圾收集设置为 null.
my understanding is that primitive types (uint, string, Number, etc.) of a class do not need to be set to null for garbage collection.
例如,我不需要在以下类中编写此 dispose()
方法:
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?
推荐答案
据我所知,关于flash player VM中GC逻辑最完整详细的解释位于Alex Harui 的博客,写于 2007 年.直接链接:GCAtomic.ppt.
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.
Grant Skinner 提供了一些关于 GC 的有用提示.
GC 逻辑处理引用和引用计数.并且由于您无法在 ActionScript 中获得对原语的引用,因此您在这方面对 GC 无能为力.
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.
编辑 刚刚想起另一篇 关于GC 和资源管理,作者:Grant Skinner.
EDIT Just remembered another nice set of articles on GC and resource management by Grant Skinner.
这篇关于ActionScript - 用于内存管理的原始/非原始对象之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!