SoundPlayer causing Memory Leaks?

Posted by Nick Udell on Stack Overflow See other posts from Stack Overflow or by Nick Udell
Published on 2010-11-05T16:27:04Z Indexed on 2011/11/12 9:50 UTC
Read the original article Hit count: 307

Filed under:
|
|
|

I'm writing a basic writing app in C# and I wanted to have the program make typewriter sounds as you typed. I've hooked the KeyPress event on my RichTextBox to a function that uses a SoundPlayer to play a short wav file every time a key is pressed, however I've noticed after a while my computer slows to a crawl and checking my processes, audiodlg.exe was using 5 GIGABYTES of RAM.

The code I'm using is as follows:

I initialise the SoundPlayer as a global variable on program start with

SoundPlayer sp = new SoundPlayer("typewriter.wav")

Then on the KeyPress event I simply call

sp.Play();

Does anybody know what's causing the heavy memory usage? The file is less than a second long, so it shouldn't be clogging the thing up too much.

© Stack Overflow or respective owner

Related posts about c#

Related posts about audio