title: As3 Memory Leak? - How to garbage collect a newed as3 Sound Object from memory?
body: <p>It looks like simply newing an as3 Sound Object, and setting its reference back to null will create a memory leak, wether or not it has been used to play a SoundChannel on it.</p>
  
  <p>For example, using next text code:</p>
  
  <pre><code>package 
  {
      import flash.display.*;
      import flash.events.*;
      import flash.media.*;
      import flash.system.*;
      import flash.utils.*;
      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);
          }
      }
  
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <p>Before
  3461120</p>
  
  <hr>
  
  <p>After new
  3604480</p>
  
  <hr>
  
  <p>After null
  3604480</p>
  
  <p>Even if the gc runs a thousand times after, the last value remains.</p>
  
  <p>So, wether or not a soundchannel is played on it, it looks like the Sound Object
  cannot be removed from memory.</p>
  
  <p>Please say I'm wrong and tell me why.
  Thanks in advance.</p>