maxl0rd/standingwave3

Memory Leak?

Opened this issue · 2 comments

Memory usage is steadily increasing over time

    public class Test4 extends Sprite
    {
        public function Test4()
        {
            stage.frameRate = 0xFFFF;
            addEventListener( Event.ENTER_FRAME, ef );
        }

        public var lastPlayer:AudioPlayer;
        public function ef( event:Event ):void
        {
            if ( lastPlayer != null )
            {
                lastPlayer.stop();
            }

            var source:IAudioSource = new SineSource(new AudioDescriptor( 44100, 2 ), 5, 440);
            var player:AudioPlayer = new AudioPlayer();
            player.play(source);   // actually make some noise

            lastPlayer = player;

            trace(Number(System.totalMemory/1024/1024).toFixed(2), Number(Sample.getAwaveMemoryUsage() / 1024 / 1024).toFixed(2));
        }
    }

Am I doing something wrong here? It is also leaking even if you play it one time, the "New" at each frame is to better show the increase.The only way I was able to fix it was to use Flash built-in "writeBytes" instead of "awave.writeBytes"

If I look at the Profiler, the ByteArrays stay in memory. A workaround:

On line 850 in "Sample.as" replace

Sample._awave.writeBytes(getSamplePointer(offset), destBytes, _descriptor.channels, numFrames);

with

destBytes.writeBytes( _awaveMemory, getSamplePointer(offset), numFrames * _descriptor.channels * 4 );

Now when I look at the profiler, it isn't leaking anymore.

I tried to play with "awave.c" using an old Alchemy toolchain since it doesn't seem to be compatible with Flascc but couldn't find a proper fix.

Hey thanks for this hint! I've started using Standingwave for my air app, and also finding bugs.

You actually show have noticed that it's function
public function writeWavBytes(destBytes:ByteArray, offset:Number=0, numFrames:Number=-1):void {...} . For me it was on line 865

E.g., in WaveFile.as I had to comment out line 57:
//fileLen += wav.position;

as it breaks the cycle below. It's very strange why would length of wav be increased after just reading a byte from it...

Also, your suggestion doesn't work when original wav files is 1 channel mono.