English 中文(简体)
行动说明3
原标题:Actionscript 3 freeing class variables

附录 我有一个像以下一类的班级结构,在那里,我有一个临时儿童,被展示,后来被替换,因此不再需要。 然而,由于儿童以前接触过多种方法,我需要成为一类变量。

因此,在替代该儿童之后,我不再需要,希望允许垃圾收集再利用这一空间。 由于变量是类别变量,因此我不能使用<代码>delete tempChild。 通常,如果再没有提及停车场,则垃圾收集将失去记忆;因此,我的问题是,如果简单地将<代码>null转让给该变量,那么就足以启动该平台。

class Test extends Sprite
{
    private var tempChild:Sprite;

    public function Test ()
    {
        tempChild = new Sprite();
        tempChild.graphics.drawRect( 0, 0, 100, 100 );
        this.addChild( tempChild );
    }

    public function replace ( obj:DisplayObject ):void
    {
        this.removeChild( tempChild );
        tempChild = null; // <-- here I want to free the variable

        this.addChild( obj );
    }
}

<<>strong>edit: 这方面的一个快速基准就是:

Test type A: Storing the Sprite reference as a private class variable
Test type B: Accessing it via child index (getChildAt)

  • Test 1: Accessing the sprite once -> B is about three times as slow as A
  • Test 2: Deleting the sprite (removeChild vs. removeChildAt) -> nearly equal, no visible performance plus from using just the index (and skipping the search for the object)
  • Test 3: Access the sprite multiple times -> A is about 20% faster than B
  • Test 4: Same as 2, but with additional sprites that fill up the childList (so removeChild actually has to search) -> B is about 25% faster than A (as expected)

由于我只一次删除了这个内容,但不得不多次加以利用,我坚持选择A(基本上像上面的法典)。

最佳回答

你的法典没有说明为什么首先被搁置起来。 假设你do需要,那么,是,指定为零 儿童会允许诱惑的对象 儿童指GCed(只要没有其他参考资料)。 但是,为什么在你可以简单地提及<条码>时,就有了“儿童”?

问题回答

暂无回答




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签