Skip to main content
Participant
October 15, 2016
Question

Why does instance of BitmapData extended class dispose it not completely?

  • October 15, 2016
  • 0 replies
  • 186 views

Why does instance of BitmapData extended class dispose it not completely?

This test led me to this conclusion:

public class DisposeTest extends Sprite

{

    private var memory:int;

    public function DisposeTest()

    {

        memory = System.privateMemory;

        var bd:BitmapData = new BitmapData(2000,2000,true,0x0);

        trackMemory(); //  16003072

        bd.dispose();  

        bd = null;       

        trackMemory(); // -16003072

    }

    private function trackMemory():void

    {

        var currentMemory:int = System.privateMemory;

        trace (currentMemory - memory);

        memory = currentMemory;

    }

}

In works fine now, but if we replace BitmapData on something like this:

public class BitmapDataExtended extends BitmapData

{

    public function BitmapDataExtended(width:int, height:int, transparent:Boolean, fillColor:uint)

    {

        super(width, height, transparent, fillColor);

    }

}

Test will show other results:

public function DisposeTest()

{

    memory = System.privateMemory;

    var bd:BitmapData = new BitmapDataExtended(2000,2000,true,0x0);

    trackMemory();     // 16072704

    bd.dispose();

    bd = null;

    trackMemory();   // -16003072

}

So, memory is allocated more, and is released as the first time.

I would like to understand why it happens and how to avoid it.

Any ideas?

This topic has been closed for replies.