Saving AS3 memory (Loaders / BitmapDatas / Bitmaps / Sprites)

I am working on reducing the memory requirements of my AS3 application. I understand that when there is no reference to an object, it is marked as a candidate for garbage collection.

Is it even worth trying to remove links to Loaders that are no longer in active use? My first thought is that it is not worth it.

Here's why: My sprites need eternal links to the bitmap images that they display (since sprites are always visible in my application). Therefore, bitmaps cannot be garbage collected. Raster maps rely on BitmapData objects for their data, so we cannot get rid of them. (Up to this point, all this is quite simple).

Here, where I'm not sure what is happening: Does BitmapData have a link to the data downloaded by the bootloader? In other words, is BitmapData essentially just a wrapper that has a link to loader.content, or data copied from loader.content to BitmapData?

If the link is supported, then I get nothing from the garbage collecting my bootloaders ...

Thoughts?

+3
source share
3 answers

AMF , Loader ( Bitmap). , BitmapData Bitmap. , Loader Bitmap, Bitmap. - BitmapData.clone().

GC. AS3?

- -, GC , . Windows, - procmon (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) , .

, , , - - Visual VM (https://visualvm.dev.java.net/), Flash.

+1

, , , : Bitmap, BitmapData , , , .

, clone() BitmapData:

()

BitmapData, .

:

private function onCreationComplete():void
{
 var urlRequest:URLRequest = new URLRequest("MyPhoto.jpg");
 var loader:Loader = new Loader();
 loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete, false, 0, true);
 loader.load(urlRequest);
}

private function loader_complete(event:Event):void
{
 var img1:Image = new Image();
 img1.source = Bitmap(event.target.content);
 addChild(img1);

 var img2:Image = new Image();
 img2.source = new Bitmap(event.target.content.bitmapData.clone());
 addChild(img2);
}

img1 - , BitmapData, . ( FlexBuilder, , .) img2 - - , , .

, . , , , . useWeakReference (. ) , , :

useWeakReference: Boolean ( = false) - , . ( ) . .

+1

, ,

public function COMPLETEListener(e:Event){
myBitmap = e.target.loader.content;
}

public function destroy(){
if(myBitmap is Bitmap){
                        myBitmap.bitmapData.dispose(); 
    }
}

0

Source: https://habr.com/ru/post/1721946/


All Articles