J
John Broderick
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
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