在.net Speech.Synthesizer内存泄漏? [英] Memory leak in .Net Speech.Synthesizer?
问题描述
我发现了一个连续的泄漏我的应用程序。检查使用内存分析器后,我发现课程是从Microsoft Speech.Synthesizer
I found a continuous leakage in my application. After examining using a memory profiler, I found the course is some object from Microsoft Speech.Synthesizer
于是我建立了一个玩具项目,以验证这一假设:
So I build up a toy project to verify the hypothesis:
//玩具为例,说明在Speech.Synthesizer对象的内存泄漏
//Toy example to show memory leak in Speech.Synthesizer object
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
}
}
而结果却证实了内存泄漏是Speech.Synthesizer
And the result actually confirmed the memory leak is from Speech.Synthesizer
Speaking...
内存:42184 KB
Memory: 42184 KB
说起... 内存:42312 KB
Speaking... Memory: 42312 KB
说起... 内存:42440 KB
Speaking... Memory: 42440 KB
说起... 内存:42568 KB
Speaking... Memory: 42568 KB
说起... 内存:42696 KB
Speaking... Memory: 42696 KB
说起... 内存:42824 KB
Speaking... Memory: 42824 KB
说起... 内存:43016 KB
Speaking... Memory: 43016 KB
说起... 内存:43372 KB
Speaking... Memory: 43372 KB
我GOOGLE了一下,发现很多人都遇到了同样的问题: 1: 在SpeechSynthesizer 常量内存泄漏 2: <一href="http://connect.microsoft.com/VisualStudio/feedback/details/664196/system-speech-has-a-memory-leak">http://connect.microsoft.com/VisualStudio/feedback/details/664196/system-speech-has-a-memory-leak
I googled it and found many others have come across the same problem: 1: Constant Memory Leak in SpeechSynthesizer 2: http://connect.microsoft.com/VisualStudio/feedback/details/664196/system-speech-has-a-memory-leak
但遗憾的是我没有找到任何解决的办法。由于它的一个问题已经问很久以前的事,所以我想问一下如果解决了没有?
but sadly I didn't find any solution to it. Since its a problem already asked long time ago, so I want to ask if its been solved or not?
非常感谢。
更新:
好像当我切换使用SAPI COM DLL而不是净Speech.Synthesizer包(虽然实际上他们是同样的事情),内存将停止泄漏。
Seems like while I switch to use SAPI COM dll rather than .Net Speech.Synthesizer package (although essentially they are the same thing), the memory stops leaking.
为什么两个调用行为(SAPI DLL VS .NET语音包)有不同的记忆行为?由于后者似乎只是一个包装,前者SAPI DLL。的
Why is the two invoke behavior (SAPI dll vs .net Speech package) have different memory behavior? As the latter seems is just a wrapper to the former SAPI dll.
static void Test2()
{
//SAPI COM component this time
SpeechLib.SpVoiceClass tts = new SpeechLib.SpVoiceClass();
tts.SetRate(5);
string text = "hello world. This is a long sentence";
//tts.Speak("helloWorld", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
while (true)
{
Console.WriteLine("Speaking...");
tts.Speak(text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
//Print private working set sieze
Console.WriteLine("Memory: {0} KB\n", (Process.GetCurrentProcess().PrivateMemorySize64 / 1024).ToString("0"));
GC.Collect();
}
}
内存:32044 KB
Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
说起... 内存:32044 KB
Speaking... Memory: 32044 KB
推荐答案
最后的解决方案:
谷歌,荷兰国际集团相关的关键字告诉我,它实际上是从微软的错误。
Google-ing relevant keywords telling me that it's actually a bug from Microsoft.
好像当我切换使用SAPI COM DLL而不是净Speech.Synthesizer包(虽然实际上他们是同样的事情),内存将停止泄漏。
Seems like while I switch to use SAPI COM dll rather than .Net Speech.Synthesizer package (although essentially they are the same thing), the memory stops leaking.
这篇关于在.net Speech.Synthesizer内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!