English 中文(简体)
Garbage Collection Test Fails?
原标题:Garbage Collection Test Fails?

如果某一物体被收集垃圾,则使用精干的假肢进行检测。 当除字典外所有提及物体之处都被删除时,我预计该词典不再有人居住。 似乎是为了目标而努力的,但就一项标准而言,它表明垃圾收集工作已经进行。 谁能告诉我我我我,我是谁?

import flash.utils.Dictionary;

var dictionary:Dictionary=new Dictionary(true);
this.addEventListener(Event.ENTER_FRAME,collectionTest);
var sprite:Sprite=new Sprite();
dictionary[sprite]=true;
sprite=null;
trace(sprite);//traces null

function collectionTest(event:Event):void{
    var cleared:Boolean = true;
    for each (var key:* in dictionary) {
        cleared = false;
    }
    if (cleared) {
        trace("Collection Success.");
    } else {
        trace("Collection Failure");
    }
}
最佳回答

我删除关键作为最佳做法:

dictionary[sprite] = null;
delete dictionary[sprite];

请注意,关键人物表示,关键人物有资格领取垃圾收集,并在收集物品时从表格中删除。 垃圾收集不可能在你的职责范围内立即进行。

理论家永远不会把弱小的强硬钥匙从桌上删除。

在关键方法和AMF序列化方面有一些已知的问题。

你们需要参与一些记忆分配,以启动垃圾收集。

我以你的榜样,创建了1 500个标准,钥匙在4个框架内被拆除:

产出:

null
Collection Failure
Collection Failure
Collection Failure
Collection Success.

例:

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.Dictionary;

    public class Test extends Sprite
    {

        public var dictionary:Dictionary = new Dictionary(true);

        public function Test()
        {
            addEventListener(Event.ENTER_FRAME, collectionTest);
            var sprite:Sprite = new Sprite();
            dictionary[sprite] = true;
            sprite = null;
            trace(sprite); //traces null
        }

        protected function collectionTest(event:Event):void
        {
            var cleared:Boolean = true;
            for each (var key:* in dictionary)
            {
                cleared = false;
            }
            if (cleared)
                trace("Collection Success.");
            else
                trace("Collection Failure");

            for(var i:uint = 0; i < 500; i++)
            {
                new Sprite();
            }
        }
    }
}
问题回答

暂无回答




相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签