Highlighted

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

New Here ,
Oct 15, 2016

Copy link to clipboard

Copied

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?

TOPICS
Performance issues

Views

129

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Oct 15, 2016

Copy link to clipboard

Copied

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?

TOPICS
Performance issues

Views

130

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 15, 2016 0

Have something to add?

Join the conversation