473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RichTextBox memory problem

I've got a problem with the RichTextBox control in .Net
where the garbage collector doesn't reclaim its memory
after I've finished with it.

My program adds a series of rtb's to the control array of a
panel to make a basic text editor. When the form that the
panel is on is closed these rtb's are still in memory.

If you want to see the probelm try this:
create a form which has a panel on it. Create a class,
myTB, which derives from RichTextBox and has a static
integer field that keeps track of the number of instances
(increment in constructor and decrement in destructor, you
can display this value somewhere on the form and set a
timer to update it). The second form has three buttons,
one (Add) adds an instance of myTB to the panel, the
second (Remove) removes myTB from the panel and the third
(Collect) calls GC.Collect().
Now click Add a couple of time to create some myTB's and
click remove to remove them, then click Collect. The count
value should stay the same.

If you want to see how it should work, try changing myTB to
derive from TextBox and try the same thing. The count will
be decremented when you force the garbage collect.

Does anyone know anymore about this or know if there is a
way to explicitly delete an object in C#. It's killing my
app but I need the richtextbox for formatting

thanks

john b

Jul 19 '05 #1
4 3436
Hi John

When you remove myTB from the panel, are you calling Dispose? Since myTB inherits from RichTextBox, it should also implement the IDisposable interface, and call its
parent class' Dispose. This will free up resources without waiting for the GC to call myTB's finalizer.

Hope that helps
-Chris

--------------------
Content-Class: urn:content-classes:message
From: "John Broderick" <jo************@snapon.ie>
Sender: "John Broderick" <jo************@snapon.ie>
Subject: RichTextBox memory problem
Date: Fri, 29 Aug 2003 09:11:48 -0700
Lines: 34
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNuSD/w+WOFRTBsT9yLoMl/CQKKoQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:106606
NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.general

I've got a problem with the RichTextBox control in .Net
where the garbage collector doesn't reclaim its memory
after I've finished with it.

My program adds a series of rtb's to the control array of a
panel to make a basic text editor. When the form that the
panel is on is closed these rtb's are still in memory.

If you want to see the probelm try this:
create a form which has a panel on it. Create a class,
myTB, which derives from RichTextBox and has a static
integer field that keeps track of the number of instances
(increment in constructor and decrement in destructor, you
can display this value somewhere on the form and set a
timer to update it). The second form has three buttons,
one (Add) adds an instance of myTB to the panel, the
second (Remove) removes myTB from the panel and the third
(Collect) calls GC.Collect().
Now click Add a couple of time to create some myTB's and
click remove to remove them, then click Collect. The count
value should stay the same.

If you want to see how it should work, try changing myTB to
derive from TextBox and try the same thing. The count will
be decremented when you force the garbage collect.

Does anyone know anymore about this or know if there is a
way to explicitly delete an object in C#. It's killing my
app but I need the richtextbox for formatting

thanks

john b

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Jul 19 '05 #2
Thanks Chris but I've tried this already. The problem is
releasing the managed rich textbox from memory rather than
any unmanaged resources it may be using, which Dispose()
will take care of. Seeing as the rich textbox is a managed
resource I shouldn't really have to worry about freeing it
up beacuase the garbage collector should get rid of it once
there are no more references to it, but this doesn't seem
to be happening.

-----Original Message-----
Hi John

When you remove myTB from the panel, are you calling Dispose? Since myTB inherits from RichTextBox, it should
also implement the IDisposable interface, and call itsparent class' Dispose. This will free up resources without waiting for the GC to call myTB's finalizer.
Hope that helps
-Chris

--------------------
Content-Class: urn:content-classes:message
From: "John Broderick" <jo************@snapon.ie>
Sender: "John Broderick" <jo************@snapon.ie>
Subject: RichTextBox memory problem
Date: Fri, 29 Aug 2003 09:11:48 -0700
Lines: 34
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNuSD/w+WOFRTBsT9yLoMl/CQKKoQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:106606NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.general

I've got a problem with the RichTextBox control in .Net
where the garbage collector doesn't reclaim its memory
after I've finished with it.

My program adds a series of rtb's to the control array of a
panel to make a basic text editor. When the form that the
panel is on is closed these rtb's are still in memory.

If you want to see the probelm try this:
create a form which has a panel on it. Create a class,
myTB, which derives from RichTextBox and has a static
integer field that keeps track of the number of instances
(increment in constructor and decrement in destructor, you
can display this value somewhere on the form and set a
timer to update it). The second form has three buttons,
one (Add) adds an instance of myTB to the panel, the
second (Remove) removes myTB from the panel and the third
(Collect) calls GC.Collect().
Now click Add a couple of time to create some myTB's and
click remove to remove them, then click Collect. The count
value should stay the same.

If you want to see how it should work, try changing myTB to
derive from TextBox and try the same thing. The count will
be decremented when you force the garbage collect.

Does anyone know anymore about this or know if there is a
way to explicitly delete an object in C#. It's killing my
app but I need the richtextbox for formatting

thanks

john b

--

This posting is provided "AS IS" with no warranties, and

confers no rights. Use of included script samples are
subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the
newsgroup/thread from which they originated.
.

Jul 19 '05 #3
Hi John,

I don't know what causes the problem, but the workaround is for you to
maintain a cache of RTBs. That way you can at least fix the upper limit.

Good luck,
Fergus
Jul 19 '05 #4
sounds like the best idea until I can get an answer for
this. thanks fergus
-----Original Message-----
Hi John,

I don't know what causes the problem, but the workaround is for you tomaintain a cache of RTBs. That way you can at least fix the upper limit.
Good luck,
Fergus
.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Walter L. Williams | last post by:
VS.NET 2K3 and .NET 1.1 I'm having a problem with RichTextBox allocating huge amounts of memory for text. I have recreated the problem in the attached sample which, when the button is pressed,...
0
by: nouno | last post by:
I am trying to spell check a richtextbox. Through code (shown below) I save the contents of the richtextbox to a rtf file, open the rtf file in Word, spell check it, save it, and then load the ftf...
2
by: KenH | last post by:
I am getting an unhandled system exception while writing to a RichTextBox. The process may run for a few hours or days before the error is generated The message is "Cannot access a disposed object...
0
by: James Manila Dot Net | last post by:
I've been having a major problem using the Rtf property of the Richtextbox. I use the RTB to generate RTF code to save it in an access database. I'm successfully able to do this. However, the...
4
by: John Broderick | last post by:
I've got a problem with the RichTextBox control in .Net where the garbage collector doesn't reclaim its memory after I've finished with it. My program adds a series of rtb's to the control array...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
1
by: eBob.com | last post by:
After a lot of debugging effort I have to conclude that it does. Or at least can. I take a substring (RichTextBox.Text.Substring) before setting SelectionStart and after and get a different...
4
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a multiline RichTextBox that I use for data logging. I'm concerned about how the AppendText method reacts when over time the maximum number of characters have been added. Do the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.