472,371 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 3301
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.