Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak? #30

Open
starburst997 opened this issue May 14, 2013 · 2 comments
Open

Memory Leak? #30

starburst997 opened this issue May 14, 2013 · 2 comments

Comments

@starburst997
Copy link

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.

@skolesnyk
Copy link

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...

@skolesnyk
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants