Memory leak with TextBox?

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I have a windows app which contains a readonly multi-line textbox.
This textbox is used to display "log" information as actions/events
occur within the application. The contents can eventually get to be
very large, as our app is often left to run overnight. We allow the
user to clear the contents of the textbox by right-clicking and
selecting "Clear" from a context menu. Within the event handler for
this menu item, I've tried clearing out the contents using the
Clear( ) method and by setting Text to "". Regardless of how I clear
it, when I monitor memory usage I notice that the memory actually goes
up after the contents are cleared. For example, in one particular
test I let the app run overnight. The next morning I cleared it, and
mem usage actually went up over 200 megabytes. I waited for a long
time to see if GarbageCollection would eventually release it, and it
did not.

I've tried other things within my code as well such as calling
ClearUndo immediately afterward. I also tried forcing garbage
collection afterward. No luck.

This is a problem for us because our users need to see this log
information, but yet it can get very big and they need the ability to
occasionally clear it.

Any ideas why clearing out a textbox causes memory usage to go up? Is
this an acknowledged memory leak within the .Net framework of which
I'm just not aware?

Thanks,
Jeff
 
Jeff said:
I have a windows app which contains a readonly multi-line textbox.
This textbox is used to display "log" information as actions/events
occur within the application. The contents can eventually get to be
very large, as our app is often left to run overnight. We allow the
user to clear the contents of the textbox by right-clicking and
selecting "Clear" from a context menu. Within the event handler for
this menu item, I've tried clearing out the contents using the
Clear( ) method and by setting Text to "". Regardless of how I clear
it, when I monitor memory usage I notice that the memory actually goes
up after the contents are cleared. For example, in one particular
test I let the app run overnight. The next morning I cleared it, and
mem usage actually went up over 200 megabytes. I waited for a long
time to see if GarbageCollection would eventually release it, and it
did not.

How do you know that it wasn't garbage collected?

Windows can choose not to take back memory from your application to
prevent expensive calls to get more memory from the OS.

Windows will not generally take back memory from your process unless the
system is low on free memory.

Alun Harford
 
Back
Top