WPF TextBox Memory Leak???

While running around in the WPF forums, I found this very interesting post… It seems that the WPF TextBox can be dangerous 🙂 – if you do not use it carefully 🙂

Basically the TextBox by default stores all text changes in an Undo Stack… This implies that every time that you change the Text of the TextBox more memory is consumed by the TextBox.

In order to fix this you have to set the UndoLimit property to 0. This would disable the Undo feature for the TextBox and thus NO MORE MEMORY CONSUMPTION

Have a nice day

11 thoughts on “WPF TextBox Memory Leak???

  1. Marlon,
    Thank you for posting this, I was checking for memory leaks in my c++ drivers for days thinking that we had a problem but it lead back to our UI wpf text boxes filling up with messaging data. Your post help me determine the cause so thank you much!

    Kieran

  2. I had been searching where my memory was leaking for quite some time now. I removed the logging to the TextBox and the memory leak was gone. I added it again and set undolimit to 0 but the memory was leaking again.

  3. Thanks, it did work for me!! I was using a wpf textbox for logging and the memory usage went up to 250MB+. Now it only uses 45MB. Thanks again.

  4. Thank-you very much – this was driving me crazy.
    By the way, I think you can achieve the same result by setting the IsUndoEnabled property to false – it works for me.

  5. Ditto!
    I had ripped out almost all of my controls trying to track down a very small memory leak… it was like < 100k per update and the application I was working on would update itself every 3 minutes…so over time…the darned thing would get up to several MBs in memory consumption when it should only be around 1.19MB (what it was when it started).
    I had tried all sorts of crazy stuff…this…happened to fix it perfectly!

    *Awesome Find*

  6. Pingback: WPF的TextBox产生内存泄露的情况 | 技术宅改变世界 G∑∑K

Leave a comment