title: AS3/Flash BitmapData .draw memory leak
body: <p>I have a large sprite...and I'm splitting it into several smaller ones with function bellow. The function works great but the memory usage of my .swf grows dramatically. </p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>private function split_sprite(sp:Sprite,the_parrent:Sprite) {
  
  
      var region:Rectangle = new Rectangle();
      region = sp.getBounds(the_parrent);
  
      var w=region.width/10;
      var h = region.height ;
  
      for (var i=0;i&lt;10;i++){ 
              //Build Matrix Transform
              var mat:Matrix= new Matrix(1,0,0,1, 0-w*i, 0 );
              sp.transform.matrix = mat;
  
              //Draw the bitmap
          var temp:BitmapData = new BitmapData(w + 2 , h, true, 0x000000);
  
  
              temp.draw(sp,mat);
  
              //Attach the BitmapData to a Bitmap Instance
              var myBitmap:Bitmap = new Bitmap(temp);
              myBitmap.smoothing = true;
              //Re apply an Inverse Matrix
              mat = new Matrix(1,0,0,1, region.x, region.y);
              myBitmap.transform.matrix = mat;
              var spp=new Sprite();
               //spp.cacheAsBitmap=true;
              spp.addChild(myBitmap);
              spp.x=w*i;
              the_parrent.addChild(spp);
  
  
      }
  
  
  
  }
  </code></pre>