Article View: borland.public.delphi.winforms.controls.using
Article #148Component.Dispose(bool) problem
From: Peter Morris [Droopy eyes softwa...
Date: Wed, 05 Jul 2006 07:28
Date: Wed, 05 Jul 2006 07:28
46 lines
2289 bytes
2289 bytes
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/
Technical Details
Message-ID:
<44ab6a34$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder1.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1eff29,4d562b5bfdb92132,start X-Google-Attributes: gid1eff29,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Peter Morris [Droopy eyes software]" <pete@NO_droopyeyes_SPAM.com> Newsgroups: borland.public.delphi.winforms.controls.using Subject: Component.Dispose(bool) problem Date: Wed, 5 Jul 2006 08:28:53 +0100 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 82.46.138.4 Message-ID: <44ab6a34$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1152084532 82.46.138.4 (5 Jul 2006 00:28:52 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder1.cambrium.nl!feeder2.cambrium.nl!feed.tweaknews.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail