Home All Groups Group Topic Archive Search About

How does SoundPlayer manage memory?

Author
24 Apr 2007 11:57 AM
Jens Weiermann
Hi,

I'm having a question regarding the memory management of the SoundPlayer
class (System.Media.SoundPlayer).
I'm using a stream as source for the sound, so the player internally calls
the PlaySound api function with the SND_MEMORY flag - together with the
SND_ASYNC flag, which is the core problem I'm trying to understand.

The byte array read from the stream get's passed as a pointer to the memory
location (by the marshaling process).

MAIN QUESTION: How does the GC (or whoever) know when the memory can be
freed? It has no idea when the playback of the sound is finished (because
the api function returns asynchronously so is still playing when
returning), but it has to free the memory at some time, doesn't it?

I've spend hours analyzing the code of SoundPlayer, but couldn't find out
how they're doing that, so if anyone has an idea, I'd be glad to hear...

Thanks!
Jens

AddThis Social Bookmark Button