Quantcast
Channel: Adobe Community : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 238792

How to garbage collect an newed as3 Sound Object from memory?

$
0
0

For example, using next text code:

 

package

{

          import flash.display.*;

          import flash.events.*;

          import flash.media.*;

          import flash.system.*;

          import flash.system.*;

 

          public class Main extends Sprite

          {

                    [Embed(source = "../data/SongScene8.mp3")] protected var SongScene8:Class;

 

                    public function Main():void

                    {

                              if (stage) init();

                              else addEventListener(Event.ADDED_TO_STAGE, init);

                    }

 

                    private function init(e:Event = null):void

                    {

                              removeEventListener(Event.ADDED_TO_STAGE, init);

 

                              System.gc();

                              trace("Before");

                              trace(System.totalMemory);

                              trace("_________________")

 

                              var sound:Sound = new SongScene8();

                              System.gc();

                              trace("After new");

                              trace(System.totalMemory);

                              trace("_________________")

 

                              sound = null;

                              System.gc();

                              trace("After null");

                              trace(System.totalMemory);

                    }

          }

 

}

 

 

The output is:

 

 

Before

3461120

_________________

After new

3604480

_________________

After null

3604480

 

 

* Even if the gc runs a thousand times after, the last, increased value remains.

* I've tested this too by importing an mp3 from an .swc, rather than from a file. The result is similar.

* Tracing System.privateMemory rather than System.totalMemory gives similar (although offset) results.

 

Wether or not a soundchannel is played on it, it looks like the Sound Object

cannot be removed from memory.

 

Please say I'm wrong and tell me why.

Thanks in advance


Viewing all articles
Browse latest Browse all 238792

Trending Articles