1 Replies - 5272 Views - Last Post: 21 November 2012 - 05:47 AM Rate Topic: -----

#1 rel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-November 12

SpeechSynthesizer memory leak problem (System.Speech.Synthesis)

Posted 19 November 2012 - 01:02 PM

Hey Guys

I have notice that when I use the SpeechSynthesizer (System.Speech.Synthesis) to read the content of the clipboard the memory utilization (In the Task Manager) goes up and up without any resource release ... how can I deal with this issue?

Imports System.Speech.Synthesis
Public Class Form1

    Public Voice As New SpeechSynthesizer
    Public ClipboardText As String = ""

    Private Sub btnRead_MouseHover(sender As Object, e As System.EventArgs) Handles btnRead.MouseHover
        My.Computer.Keyboard.SendKeys("^c", True)
        TxtClipboard.Text = Clipboard.GetText
        ClipboardText = Clipboard.GetText

    End Sub

    Private Sub btnPause_MouseHover(sender As Object, e As System.EventArgs) Handles btnPause.MouseHover
    End Sub

    Private Sub btnStop_MouseHover(sender As Object, e As System.EventArgs) Handles btnStop.MouseHover
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    End Sub

End Class

Is This A Good Question/Topic? 0
  • +

Replies To: SpeechSynthesizer memory leak problem (System.Speech.Synthesis)

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 233
  • View blog
  • Posts: 770
  • Joined: 19-October 11

Re: SpeechSynthesizer memory leak problem (System.Speech.Synthesis)

Posted 21 November 2012 - 05:47 AM

I suggest small changes:
  • remove timer and background worker - you don't need them;
  • move Voice.SpeakAsync(ClipboardText) to btnRead.MouseHover event handler;
  • on Form.Closed event handler dispose Voice (Voice.Dispose()), because it is bound to unmanaged resources.

Memory usage will increase until all the needed data is read and behind-the-scene prepared for speaking by SpeechSynthesizer class, then it will settle.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1