我在申请中发现了连续泄漏.在使用内存分析器进行检查后,我发现该课程是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 …