Constant Memory Leak in SpeechSynthesizer Constant Memory Leak in SpeechSynthesizer wpf wpf

Constant Memory Leak in SpeechSynthesizer


This is a know issue in the Speak method. A structure called SPVTEXTFRAG gets created and never destroyed.

Details here : http://connect.microsoft.com/VisualStudio/feedback/details/664196/system-speech-has-a-memory-leak


I can confirm this observation. I was pulling my hair out trying fo figure out where my program was leaking and it is the .SPEAK method in System.speech

I have converted an app that used the COM-based Speech objects to use the new System.Speech .Net library in .Net 3.5. Sounded like the right way to move forward to using all manged code within the .Net app. The app suddenly had a small mem leak.

I broke this down into 2 simple apps that convert "this is a test" to a WAV file of spoken words. One uses the COM-based speech objects, the other uses System.Speech. I ran them for 24 hours, each creating the WAV about 200,000 times.

COM based speech objects: no mem leak. Mem usage of app peaked at 13MB after about 40 minutes

System.speech: slow leak, nice and linear. Ran from about 14MB to 45MB in 24 hours


SendAsync() from the Ping also leaks. The solution there is to cast the sender as IDisposable first. So maybe the following also works here.

((IDisposable)spk).Dispose();