473,686 Members | 3,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3491
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+WOFRTBsT9yLoM l/CQKKoQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:106606
NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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+WOFRTBsT9yLoM l/CQKKoQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:106606NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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
1830
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, will create a ~33MB file and load it into the RichTextBox. If you watch the memory in Task Manager, before the button it consumes ~15MB max, but after it's finished, the memory is upwards of 140MB. Immediately invoking the GC doesn't seem to...
0
3232
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 file back into the ricktextbox using loadfile. The problem is that the richtextbox seems to remain bound to the rtf file. If I make a change in the richtextbox after spell checking, the changes are successfully saved to the database but if the...
2
3178
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 named RICHTEXTBOX." A check of the stack trace indicates the error is from the DLL that controls writing to the RTB. The form has not been closed and the line of code referenced is in a catch block that writes any error to this form's RTB (named...
0
2143
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 moment I retrieve the RTF code from the database back to the Rtf property, it ignores any tags that refer to bullet information. I don't understand why. This is the code that is stored in the database generated by the Richtextbox:
4
564
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 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,
0
11144
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 STRUCT_RECT
0
2054
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 inside with panel. The RichTextBox keep inside with other panel. The panel height and width is same with RichTextBox. The RichTextBox both scrolling options are make it as false. I done the coding for RichTextBox's height to fit with...
1
1476
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 result. The second result begins two characters to the right of the first. In an earlier version of the program I did not have this problem. But in that version the RichTextBox actually appeared on a form. In the version of the program with the...
4
13455
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 oldest characters it contains start rolling off the top into the bit bucket, does it simply start silently ignoring appends until some characters, are deleted, or does some kind of exception get thrown? I've heard numerous opinions on what the...
0
8514
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8766
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6439
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.