Dumping a ByteArray making use of Actionscript 3

Just how do I vigorously unload a ByteArray from memory making use of ActionScript 3?

I have actually attempted the adhering to:

// First non-working solution
byteArray.length = 0;
byteArray = new ByteArray();

// Second non-working solution
for ( var i:int=0; i < byteArray.length; i++ ) {
    byteArray[i] = null;
2019-05-07 00:15:19
Source Share
Answers: 5

I do not assume you have anything to bother with. If System.totalMemory drops you can loosen up. It might quite possibly be the OS that does not redeem the freshly released memory (in expectancy of the next time Flash Player will certainly request for even more memory).

Attempt doing another thing that is really memory extensive and also I'm certain that you'll see that the memory alloted to Flash Player will certainly decrease and also be made use of for the various other procedure rather.

As I've recognized it, memory monitoring in modern-day OS is isn't instinctive from the viewpoint of considering the quantities alloted per procedure, or perhaps the complete quantity alloted.

When I've utilized my Mac for 5 mins 95% of my 3 GB RAM is made use of, and also it will certainly remain in this way, it never ever drops. That is simply the means the OS takes care of memory.

As long as it is not required in other places also procedures that have actually given up still have actually memory appointed to them (this can make them release quicker the next time, as an example).

2019-05-30 08:47:55

Have an appearance at this write-up


IANA actionscript designer, nonetheless the sensation I'm obtaining is that, due to the fact that the garbage man could not run when you desire it to.

Therefore. http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/

So I would certainly advise experimenting with their collection code and also see if it aids

private var gcCount:int;
private function startGCCycle():void{
    gcCount = 0;
    addEventListener(Event.ENTER_FRAME, doGC);
private function doGC(evt:Event):void{
    if(++gcCount > 1){
        removeEventListener(Event.ENTER_FRAME, doGC);
        setTimeout(lastGC, 40);
private function lastGC():void{
2019-05-08 20:46:00

I think you have actually addressed your very own inquiry ...

System.totalMemory offers you the complete quantity of memory being "made use of", not alloted. It is exact that your application might just be making use of 20mb, yet it has 5mb that is free for future appropriations.

I'm not exactly sure if the Adobe docs would certainly clarify the manner in which it takes care of memory ...

2019-05-08 20:27:25

(I'm negative concerning this, yet ...)

AS3 makes use of a non - deterministic trash. Which suggests that unreferenced memory will certainly be liberated whenever the runtime seems like it (commonly not unless there's a factor to run, given that it's a pricey procedure to execute). This coincides strategy made use of by the majority of modern-day waste accumulated languages (like C# and also Java too).

Thinking there are nothing else referrals to the memory indicated by byteArray or the things within the array itself, the memory will certainly be released at some time after you exit the extent where byteArray is proclaimed.

You can compel a trash, though you actually should not. If you do, do it just for screening ... if you do it in manufacturing, you'll injure performance far more than aid it.

To compel a GC, shot (yes, two times) :


You can read more here.

2019-05-08 20:12:06

Unfortunately when it involves memory monitoring in Flash/actionscript there isn't a great deal you can do. ActionScript was made to be very easy to make use of (so they really did not desire individuals to need to bother with memory monitoring)

The adhering to is a workaround, as opposed to developing a ByteArray variable shot this.

var byteObject:Object = new Object();

byteObject.byteArray = new ByteArray();


//Then when you are finished delete the variable from byteObject
delete byteObject.byteArray;

Where byteArray is a vibrant building of byteObject, you can free the memory that was alloted for it.

2019-05-08 20:08:35