How are embedded images in action script handled at runtime-Collection of common programming errors
My understanding is that embedded images are compressed and stored as part of the application binary (SWF file) and that upon the instantiation of a class with embedded image properties, all of the images are loaded at once and they stay in memory, so that they are readily available and don’t require asynchronous loading. This of course sounds intuitive, but is it definitely correct?
For instance if I’m using a class that defines
class BunchOfEmbeddedImages {
[Embed(source="some_image_1.png")]
private var someImage1:Class;
.
.
.
[Embed(source="some_image_100.png")]
private var someImage100:Class;
}
Assuming each image is 100KB, when an instance of this class is created, does the application now 10000KB (more since they’re decompressed)?
-
I figured I might as well answer my own question. Although I can’t find the original document I read to find the answer to this topic (it was a performance optimization doc from adobe), I did find that no matter what, that since the entire SWF is loaded into memory, all embedded assets are consuming memory as well, regardless of if the class that embeds them is instantiated or not. This does make perfect sense as embedded images are will all reference the same bitmap data, but will be referenced by different DisplayObject Instances. This allows n DisplayObjects in different parts of the display list to show the same image, but not consume n-times the memory of the bitmap.