Thursday, October 20, 2005

Flash 8 - BitmapData.dispose by Tink

Tink contributed this example using flash.display.BitmapData.dispose. The example shows how to dispose of BitmapData memory directly. The dispose method was created to allow developers to free memory within BitmapData objects without relying on the garbage collector.


For every pixel within a BitmapData Object, the player allocates 4bytes of memory per pixel, essentially 1 byte for Red, Green, Blue, Alpha data within each pixel. If you create a 300px X 300px BitmapData Instance, the player has used 360,000 bytes or 351 kilobytes of memory. The problem is that this memory left alone will not get freed in the garbage collector until all references to the BitmapData instance are removed combined with an incremental sweep of the garbage collector. Instead of waiting for these to occur, you can use 'dispose' to directly free the allocated memory within the player.

In the above example, pressing dispose frees the memory allocated to the BitmapData object showing on the stage in red.

This example is available with full source and documentation within Flash® by Example.

More to come.

Ted :)

0 Comments:

Post a Comment

<< Home