相关疑难解决方法(0)

.Net Speech.Synthesizer中的内存泄漏?

我在申请中发现了连续泄漏.在使用内存分析器进行检查后,我发现该课程是Microsoft Speech.Synthesizer中的一些对象

所以我建立了一个玩具项目来验证这个假设:

//在Speech.Synthesizer对象中显示内存泄漏的玩具示例

static void Main(string[] args)
{
    string text = "hello world. This is a long sentence";
    PromptBuilder pb = new PromptBuilder();
    pb.StartStyle(new PromptStyle(PromptRate.ExtraFast));
    pb.AppendText(text);
    pb.EndStyle();
    SpeechSynthesizer tts = new SpeechSynthesizer();

while (true)
{
    //SpeechSynthesizer tts = new SpeechSynthesizer();
    Console.WriteLine("Speaking..."); 
    tts.Speak(pb);

    //Print private working set sieze
    Console.WriteLine("Memory: {0} KB\n", (Process.GetCurrentProcess().PrivateMemorySize64 / 1024).ToString("0"));

    //tts.Dispose();    //also this doesn't work as well
    //tts = null;

    GC.Collect();   //a little help, but still leaks
}
}
Run Code Online (Sandbox Code Playgroud)

结果实际证实内存泄漏来自Speech.Synthesizer

Speaking...
Run Code Online (Sandbox Code Playgroud)

内存:42184 KB

说到......内存:42312 KB

说到......内存:42440 …

.net c# memory-leaks sapi speech-synthesis

8
推荐指数
1
解决办法
2577
查看次数

标签 统计

.net ×1

c# ×1

memory-leaks ×1

sapi ×1

speech-synthesis ×1