|
| Component.Dispose(bool) problem |
 |
Wed, 5 Jul 2006 08:28:53 +0100 |
1) Create a new Delphi WinForm app (dotnet)
2) Drop any non-visual component onto the form
3) Put a break line on the following first line of the following method
procedure TWinForm.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
4) Run the app
5) Close the app
I was surprised to see "Components = nil", so Dispose is never
executed on
any of the components dropped onto a form. Am I wrong about this? My
Component descendant overrides Dispose(bool) but it is never called, it is
exactly the same in a C# WinForm app too.
"components" is declared but never created. The designer code should
additionally have
components = new System.ComponentModel.Container();
each component should be created and then have the following line of code
components.Add(newComponent, newComponent.Name);
As a result Dispose(true) is never called on the components when the owning
form closes and as a result it's managed resources do not get cleaned up.
--
Pete
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
http://www.droopyeyes.com
My blog
http://blogs.slcdug.org/petermorris/
|
| Post Reply
|
| Re: Component.Dispose(bool) problem |
 |
5 Jul 2006 09:05:22 -0700 |
At 16:20:48, 05.07.2006, Joanna Carter [TeamB] wrote:
> "Chee Wee Chua (Borland Support)" <cwchua@borland.com> a
écrit dans le
> message de news: 9fhna2pkqiduvcm3r0i40ofgbbdek9j6o2@4ax.com...
>
> > I do not see a component named "any non-visual" ;o)
>
> Looks like you are expecting a visit from Rudy to fix the broken teeth
> acquired from a smack in the mouth for that remark :-)
I don't do visits. He'll have to come to my clinic. <g>
--
Rudy Velthuis [TeamB] http://rvelthuis.de/
"That is the saving grace of humor, if you fail no one is laughing at
|
| Post Reply
|
| Re: Component.Dispose(bool) problem |
 |
Wed, 5 Jul 2006 14:06:04 +0100 |
Hi Chee Wee
These are the exact steps, honest :-)
1) Create a new Delphi WinForm app (dotnet)
2) Drop any non-visual component onto the form
3) Put a break line on the first line of the Dispose method
You will see that "components" is always null, so components.Dispose
is not
called. Therefore MyComponent.Dispose is not called until garbage
collected, at which point I cannot rely upon my references being valid for
me to clean them up.
public class MyComponent: System.ComponentModel.Component
{
protected override void Dispose(bool disposing)
{
if (disposing)
//Do anything here, but it will never get called!
}
}
It's exactly the same in VS2003 but seems to be fixed in VS2005.
Unfortunately it means that my ECO components are leaving UndoBlocks lying
around + taking up memory because the component is never disposed.
--
Pete
====
Audio compression components, DIB graphics controls, ECO extensions,
FastStrings
http://www.droopyeyes.com
My blog
http://blogs.slcdug.org/petermorris/
|
| Post Reply
|
| Re: Component.Dispose(bool) problem |
 |
5 Jul 2006 14:21:01 -0700 |
At 23:15:06, 05.07.2006, chewy wrote:
> On Wed, 5 Jul 2006 15:20:48 +0100, "Joanna Carter [TeamB]"
> <joanna@not.for.spam> wrote:
>
> > Looks like you are expecting a visit from Rudy to fix the broken
> > teeth acquired from a smack in the mouth for that remark :-)
>
> The guy doesn't do house visits... Must be getting too rich, too fat,
> or have feet too big to do some walking...
Luggage is generally limited to 35kg, and my chair alone weighs more than
that.
--
Rudy Velthuis [TeamB] http://rvelthuis.de/
"First you forget names, then you forget faces. Next you forget to
pull your zipper up and finally, you forget to pull it down."
|
| Post Reply
|
| Re: Component.Dispose(bool) problem |
 |
Wed, 5 Jul 2006 15:20:48 +0100 |
"Chee Wee Chua (Borland Support)" <cwchua@borland.com> a écrit
dans le
message de news: 9fhna2pkqiduvcm3r0i40ofgbbdek9j6o2@4ax.com...
| I do not see a component named "any non-visual" ;o)
Looks like you are expecting a visit from Rudy to fix the broken teeth
acquired from a smack in the mouth for that remark :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
|
| Post Reply
|
|
|
|
|
|
|
|
|
|