PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Memory leak with TextBox?

Reply

Memory leak with TextBox?

 
Thread Tools Rate Thread
Old 04-06-2008, 01:25 PM   #1
Jeff
Guest
 
Posts: n/a
Default Memory leak with TextBox?


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
  Reply With Quote
Old 12-06-2008, 11:58 PM   #2
Alun Harford
Guest
 
Posts: n/a
Default Re: Memory leak with TextBox?

Jeff wrote:
> 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
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off