Search code examples
performanceactionscript-3flashmemoryflashdevelop

Loading images takes my direct memory up | AS3


I'm only loading bitmaps, without even adding them to the stage, each image takes my direct memory up. Large images will take even more memory, so I'm wondering how to keep direct memory low even after loading those bitmaps, or maybe I'm doing here something wrong or missing something?

    var myBitmapHolder:Bitmap; 

    var bitmapLoader:Loader = new Loader();
    bitmapLoader.addEventListener(Event.COMPLETE, bitmapLoaded);
    bitmapLoader.load(new URLRequest("myBitmap.png");

    private function bitmapLoaded(e:Event):void {
        myBitmapHolder = e.currentTarget.content;
    }

After loading the bitmap, I'm storing it using myBitmapHolder to access it upon request. I'm using more than 30 bitmaps, works the same as the example above for each image separately.


Solution

  • so ... there is no free resource - you have to load all in the memory, or you have to load then unload each or few bitmaps. That will 'eat' some other resource like cpu and network traffic etc.
    First you have to remove 'bitmapLoader' Event.COMPLETE listener in 'bitmapLoaded' function: bitmapLoader.removeEventListener(Event.COMPLETE, bitmapLoaded); }
    You have to be sure that you load the bitmap/s once.
    Look at this: AS3 - Memory management and What are good memory management techniques in Flash/as3.
    You can look at : imageDecodingPolicy also.