Constante vazamento de memória no SpeechSynthesizer

Eu desenvolvi um projeto que eu gostaria de lançar que usa c #, WPF e o objeto System.Speech.Synthesizer. O problema que impede o lançamento deste projeto é que, sempre que o SpeakAsync é chamado, ele deixa um vazamento de memória que cresce ao ponto de uma eventual falha. Acredito que limpei corretamente depois de usar esse objeto, mas não consigo encontrar uma cura. Eu executei o programa através do Ants Memory Profiler e informa que WAVEHDR e WaveHeader estão crescendo a cada chamada.

Eu criei um projeto de amostra para tentar identificar a causa, mas ainda estou perdido. Qualquer ajuda seria apreciada.

O projeto usa o VS2008 e é um projeto c # WPF direcionado ao .NET 3.5 e Qualquer CPU. Você precisa adicionar manualmente uma referência ao System.Speech.

Aqui está o código:

<Window x:Class="SpeechTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
    <StackPanel Orientation="Vertical">

        <Button Content="Start Speaking" Click="Start_Click" Margin="10" />
        <Button Content="Stop Speaking" Click="Stop_Click" Margin="10" />
        <Button Content="Exit" Click="Exit_Click" Margin="10"/>

    </StackPanel>
</Grid>



// Start of code behind
using System;
using System.Windows;
using System.Speech.Synthesis;

namespace SpeechTest
{
    public partial class Window1 : Window
    {

        // speak setting
        private bool speakingOn = false;
        private int curLine = 0;
        private string [] speakLines = {
            "I am wondering",
            "Why whenever Speech is called",
            "A memory leak occurs",
            "If you run this long enough",
            "It will eventually crash",
            "Any help would be appreciated" };

        public Window1()
        {
            InitializeComponent();
        }

        private void Start_Click(object sender, RoutedEventArgs e)
        {
            speakingOn = true;
            SpeakLine();
        }

        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            speakingOn = false;
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }

        private void SpeakLine()
        {
            if (speakingOn)
            {
                // Create our speak object
                SpeechSynthesizer spk = new SpeechSynthesizer();
                spk.SpeakCompleted += new EventHandler(spk_Completed);
                // Speak the line
                spk.SpeakAsync(speakLines[curLine]);
            }
        }

        public void spk_Completed(object sender, SpeakCompletedEventArgs e)
        {
            if (sender is SpeechSynthesizer)
            {

                // get access to our Speech object
                SpeechSynthesizer spk = (SpeechSynthesizer)sender;
                // Clean up after speaking (thinking the event handler is causing the memory leak)
                spk.SpeakCompleted -= new EventHandler(spk_Completed);
                // Dispose the speech object
                spk.Dispose();
                // bump it
                curLine++;
                // check validity
                if (curLine >= speakLines.Length)
                {
                    // back to the beginning
                    curLine = 0;
                }
                // Speak line
                SpeakLine();
            }
        }
    }
}




Eu executo este programa no Windows 7 de 64 bits e ele será executado e, eventualmente, será interrompido ao tentar criar um novo objeto SpeechSynthesizer. Quando executada no Windows Vista de 64 bits, a memória aumenta de um ponto inicial de 34k para cerca de 400k e cresce.

Alguém pode ver algo no código que possa estar causando isso ou isso é um problema com o próprio objeto Speech.

Qualquer ajuda seria apreciada.

questionAnswers(4)

yourAnswerToTheQuestion