Bitmap Caching and Memory Usage
Bitmap Caching and Memory Usage
Bitmap caching naturally makes Flash Player use more memory, because for every cached movie clip the player has to store the vector data and the additional bitmap equivalent in memory. When you turn bitmap caching off for any particular movie clip, Flash removes its bitmap representation from memory.
You should be concerned about the amount of memory that your Flash file uses, because it can affect the performance of other applications that are running on the same computer. The more memory Flash Player uses, the less memory that is available for other programs to run effectively.
Computers only have so much memory available to them in the form of RAM. Most computers nowadays have at least 256MB of RAM. The operating system may provide more memory when required in the form of virtual memory. Flash Player should never use that much memory, but now, with the various new bitmap-related features added to the player, Flash files can consume large amounts of memory at a time, so you should make an effort to minimize memory usage.
Before we talk about the specifics of bitmap caching and memory usage, here’s a little background information. As you probably know, a bitmap is made up of pixels. It can be thought of as a grid of color values, which designate a particular color for each and every pixel. Each pixel is a cell in the grid. A100 x 100 pixel bitmap can be described by a grid of 10,000 color values, one for each pixel.
Each color value in a bitmap is a binary number. A binary number is made up of bits, whose values can be either 0 or 1. This binary number will differ in length, depending upon the color depth of the bitmap. The color depth of a bitmap determines the range of possible color values that can be used in each pixel. For example, each pixel in a 24-bit image can be one of roughly 16.8 million colors. Those colors are formed by mixing together varying quantities of three primary colors: red, green, and blue. The three main colors are called channels. It follows that:
- Each channel can have 256 possible values (0–255).
- 256 * 256 * 256 = 16.8 million
- 256 decimal is 11111111 in binary.
- This binary number is 8 bits long. 8 bits is 1 byte.
Therefore each channel in a color uses 1 byte.
The bitmaps that are created by Flash Player when it converts a movie clip into a surface have a 32-bit color depth. 32-bit images have four channels: red, green, blue, and an additional alpha channel.
Therefore the color value for each pixel in a surface created by Flash Player is 32 bits long, or 4 bytes.
4 * 8 = 32 bit
The bitmap that is created by Flash Player to represent the visual state of a movie clip when you turn bitmap caching on will have the same dimensions (width and height) as the movie clip.
A cached movie clip that is 100 x 100 pixels has 10,000 pixels.
100 * 100 = 10,000 pixels
Each of those pixels will be 32 bits or 4 bytes. Therefore the movie clip will use an extra 40,000 bytes of memory.
10,000 * 4 = 40,000 bytes
There are 1024 bytes in 1 kilobyte (K). So, 40,000 bytes can also be said to be roughly 40 kilobytes (40K).