PlaySound handle leak?

PlaySound handle leak?

Post by Paul Rober » Tue, 29 Jun 2004 05:19:18

I've been investigating what appeared to be a handle leak in my app, and
have finally narrowed it down to a single MM api call: PlaySound

If I create a trivial project and make a simple call, e.g.
::PlaySound( "SystemExclamation", hMod, SND_ASYNC | SND_ALIAS )

then the handle count steadily grows... and grows..

I'm running XP Pro. The sound on my machine is NForce2 Soundstorm (with
recent NVidia drivers). I've tried this on a different machine (same OS,
different sound hardware and drivers) and the "leak" is still there,
although handle consumption is slower (1 handle not released per play).

Is this something I should worry about, or will Windows eventually do
some kind of cleanup? Is there some kind of cleanup I should be doing?

P.S. you don't even need code to see MM handle consumption: just bring
up the WinXP sound cpl, switch to the sound tab, select a system sound
and keep pressing play. Open Task Manager while you're doing this and
watch the handle count for Rundll32 steadily rise.

PlaySound handle leak?

Post by Chris P. [ » Wed, 30 Jun 2004 00:53:44

Definately sounds like a bug, but I'm not sure what the actual handle type
is. Does it only occur with SND_ASYNC? If so it could be the thread handle
for the thread that is created to play the sound.


PlaySound handle leak?

Post by Paul Rober » Wed, 30 Jun 2004 06:44:00

On my development machine SND_SYNC and SND_ASYNC seem to behave much the
same with regard to handle consumption. There's an initial surge in
handles when the first call is made (it's about 3 handles greater with
ASYNC). Thereafter, for both sync and async the handle count increases
by 7 while the sound is playing, then falls back by 4 - a net increase
of 3 handles per sound played.

Interestingly, both sync and async calls cause the thread count to
increase by one for the duration of the sound but, as expected,
PlaySound returns almost immediately for async vs after the sound for sync.

Repeated the tests on my other PC, and got similar results (in this
case, increase of 4 handles while playing, then a drop of 3, net
increase of 1 - same async/sync)