Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SpeechSynthesizer memory leak

SpeechSynthesizer memory leak

Scheduled Pinned Locked Moved C#
performance
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FocusedWolf
    wrote on last edited by
    #1

    Was wondering if anyone knows of a workaround for the annoying memory leak in SpeechSynthesizer.

    D D 2 Replies Last reply
    0
    • F FocusedWolf

      Was wondering if anyone knows of a workaround for the annoying memory leak in SpeechSynthesizer.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Don't use it? Seriously, you're going to have to provide a link to the problem you're talking about, and there's more than one SpeechSynthesizer running around...

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Don't use it? Seriously, you're going to have to provide a link to the problem you're talking about, and there's more than one SpeechSynthesizer running around...

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        F Offline
        F Offline
        FocusedWolf
        wrote on last edited by
        #3

        Sorry i thought everyone knew about this :) Here's from some other people that have experienced it: http://stackoverflow.com/questions/2204012/constant-memory-leak-in-speechsynthesizer[^] Little translation action for this one: http://translate.googleusercontent.com/translate_c?hl=en&sl=de&u=http://www.eggheadcafe.com/software/aspnet/34136900/memoryleak-in-speechsynth.aspx&prev=/search%3Fq%3Dspeechsynthesizer%2Bmemory%2Bleak%26hl%3Den&rurl=translate.google.com&twu=1&usg=ALkJrhhmXs1dqrvH8fgXvkgr_s4qn1wQkA[^] To summarize the effect, the more words that the SpeechSynthesizer .net framework object has to read, the more megabytes of memory it consumes. It's not long before it's soaking up a few hundred mb. First effect, which sets on rather quickly, is the reader gets slower and slower. I have tried various hacky attempts to dispose and create new objects, but it wasn't 100% successful (besides introduces a noticeable delay). This is from the first link:

        what happens if you don't create a new SpeechSynthesizer object on each pass? – Eric Brown Feb 19 at 20:50

        Eric, I tried it that way the first time through and it is actually worse. This was why I tried creating and destroying the object with each call. It did improve slightly, but still doesn't solve the issue. Any call to SpeechSynthesizer leaves behind WAVEHDR and WaveHeader objects that grows the private memory until it crashes. – DudeFX Feb 19 at 23:34

        D 1 Reply Last reply
        0
        • F FocusedWolf

          Sorry i thought everyone knew about this :) Here's from some other people that have experienced it: http://stackoverflow.com/questions/2204012/constant-memory-leak-in-speechsynthesizer[^] Little translation action for this one: http://translate.googleusercontent.com/translate_c?hl=en&sl=de&u=http://www.eggheadcafe.com/software/aspnet/34136900/memoryleak-in-speechsynth.aspx&prev=/search%3Fq%3Dspeechsynthesizer%2Bmemory%2Bleak%26hl%3Den&rurl=translate.google.com&twu=1&usg=ALkJrhhmXs1dqrvH8fgXvkgr_s4qn1wQkA[^] To summarize the effect, the more words that the SpeechSynthesizer .net framework object has to read, the more megabytes of memory it consumes. It's not long before it's soaking up a few hundred mb. First effect, which sets on rather quickly, is the reader gets slower and slower. I have tried various hacky attempts to dispose and create new objects, but it wasn't 100% successful (besides introduces a noticeable delay). This is from the first link:

          what happens if you don't create a new SpeechSynthesizer object on each pass? – Eric Brown Feb 19 at 20:50

          Eric, I tried it that way the first time through and it is actually worse. This was why I tried creating and destroying the object with each call. It did improve slightly, but still doesn't solve the issue. Any call to SpeechSynthesizer leaves behind WAVEHDR and WaveHeader objects that grows the private memory until it crashes. – DudeFX Feb 19 at 23:34

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          FocusedWolf wrote:

          Sorry i thought everyone knew about this

          I do. But since Microsoft isn't the only vendor for speech synthesis software, I like to make sure which library we're talking about.

          FocusedWolf wrote:

          To summarize the effect, the more words that the SpeechSynthesizer .net framework object has to read, the more megabytes of memory it consumes. It's not long before it's soaking up a few hundred mb. First effect, which sets on rather quickly, is the reader gets slower and slower. I have tried various hacky attempts to dispose and create new objects, but it wasn't 100% successful (besides introduces a noticeable delay). This is from the first link:

          I didn't use the code you linked to, but I wrote my own app and couldn't come up with a memory leak. I'm assuming the code you linked to is yours. It's written kind of funny. I'd skip destroying and creating a new synth every time you want to say something and go back to creating a single synth object you can use at any time. I'm not seeing the problem you're talking about in my code and can't find any reference to any kind of memory leak anywhere on the web.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          F 1 Reply Last reply
          0
          • D Dave Kreskowiak

            FocusedWolf wrote:

            Sorry i thought everyone knew about this

            I do. But since Microsoft isn't the only vendor for speech synthesis software, I like to make sure which library we're talking about.

            FocusedWolf wrote:

            To summarize the effect, the more words that the SpeechSynthesizer .net framework object has to read, the more megabytes of memory it consumes. It's not long before it's soaking up a few hundred mb. First effect, which sets on rather quickly, is the reader gets slower and slower. I have tried various hacky attempts to dispose and create new objects, but it wasn't 100% successful (besides introduces a noticeable delay). This is from the first link:

            I didn't use the code you linked to, but I wrote my own app and couldn't come up with a memory leak. I'm assuming the code you linked to is yours. It's written kind of funny. I'd skip destroying and creating a new synth every time you want to say something and go back to creating a single synth object you can use at any time. I'm not seeing the problem you're talking about in my code and can't find any reference to any kind of memory leak anywhere on the web.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            F Offline
            F Offline
            FocusedWolf
            wrote on last edited by
            #5

            No i didn't write that code... it's just a random google result from searching for other people experiencing this problem. Anyway recently i changed the code to just use the class the way people would expect to use it (i.e. no hacky tricks to fight the memory leak) and the memory consumption was about 400 kb/s. Some things you can try to see the effect is give the reader a few pages of words to read, and set the Rate property to some number like 7 or 10. Subscribing to these events may also be a factor (SpeakCompleted and SpeakProgress). I've noticed that if i just let the program go then it will get to the point of holding about 40-50 mb of ram where it almost stops allocating, and a few minutes later it will get a few more mb. So i'm wondering if this is a true memory leak or by design (i.e. if it has to read a lot then it allocates all this memory). However one thing i notice is when it finished reading, it doesn't flush the memory because the program is still holding onto 46 mb.

            D 1 Reply Last reply
            0
            • F FocusedWolf

              No i didn't write that code... it's just a random google result from searching for other people experiencing this problem. Anyway recently i changed the code to just use the class the way people would expect to use it (i.e. no hacky tricks to fight the memory leak) and the memory consumption was about 400 kb/s. Some things you can try to see the effect is give the reader a few pages of words to read, and set the Rate property to some number like 7 or 10. Subscribing to these events may also be a factor (SpeakCompleted and SpeakProgress). I've noticed that if i just let the program go then it will get to the point of holding about 40-50 mb of ram where it almost stops allocating, and a few minutes later it will get a few more mb. So i'm wondering if this is a true memory leak or by design (i.e. if it has to read a lot then it allocates all this memory). However one thing i notice is when it finished reading, it doesn't flush the memory because the program is still holding onto 46 mb.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              If you're looking at this "used" in TaskManager, don't. Use Performance Monitor instead. Task Manager is howing you what the .NET CLR has reserved for your app, not what your app is actually using.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              1 Reply Last reply
              0
              • F FocusedWolf

                Was wondering if anyone knows of a workaround for the annoying memory leak in SpeechSynthesizer.

                D Offline
                D Offline
                DudeFX557
                wrote on last edited by
                #7

                I am actually the one who wrote the code linked to on StackOverflow. If you read the notes on this post you will see that i originally wrote the code so that it only used one instance of the SpeechSynthesizer object. This memory leak is very much a problem with the Speak or SpeakAsync method making the System.Speech object unusable in ANY project. If you run the code you will see it will QUICKLY cause Windows 7.0 (couple hours) to crash, and will cause Vista to crash after about 20 hours. I have both versions of the code linked here in a forum post on the MSDN site. http://social.msdn.microsoft.com/Forums/en-US/Offtopic/thread/ee7bd34f-20c2-4a75-9d5a-a0c5e7f1a9b2[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups