SoundPlayer causing Memory Leaks?
- by Nick Udell
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.