Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Form.Dispose

9 views
Skip to first unread message

Daniel Moth

unread,
Feb 18, 2003, 10:14:07 AM2/18/03
to
Hi

When creating a form, a Dispose method gets automatically generated.

I notice that on the desktop this method gets called when the form closes.
With the CF the method is never called. Is this a fact or am I missing
something please?

Cheers
Daniel


Ginny Caughey [MVP]

unread,
Feb 18, 2003, 11:15:23 AM2/18/03
to
Daniel,

The garbage collectors may work differently betwee the compact and desktop
frameworks. What exactly do you need to happen? For example, would explicitly
releasing a resource in a Closing event handler do what you need?
--
Ginny Caughey
Windows Embedded MVP

"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:ezyefC21CHA.2912@TK2MSFTNGP10...

Daniel Moth

unread,
Feb 18, 2003, 11:30:53 AM2/18/03
to
Yes I work around it by catching the Closed event (which previously I
didn't) and putting my clean up code (releasing unmanaged resources) in
there...

Its just a shame I have to code differently on the 2 platforms and I was
hoping that I was missing something...

Cheers
Daniel

"Ginny Caughey [MVP]" <ginny....@wasteworks.com> wrote in message
news:ujknjj21CHA.2216@TK2MSFTNGP09...

Ginny Caughey [MVP]

unread,
Feb 18, 2003, 11:53:02 AM2/18/03
to
Daniel,

I understand what you're saying, but I think it's actually cleaner to do that on
the desktop too. ;-) In any case, since Microsoft monitors this newsgroup, I'm
sure they'll see your message.


--
Ginny Caughey
Windows Embedded MVP

"Daniel Moth" <dmo...@hotmail.com> wrote in message

news:Or$fZt21CHA.2372@TK2MSFTNGP09...

Daniel Moth

unread,
Feb 19, 2003, 3:37:23 AM2/19/03
to
Ginny

I am not sure its better since I have to add an extra method to my code
which apart from code bloat it results at runtime extra method call and
event handler... As unimportant as it is, I'd still be interested at reasons
why its cleaner though...

Hopefully MS will confirm the difference and put the philosophical
discussion to sleep :-)

Cheers
Daniel

"Ginny Caughey [MVP]" <ginny....@wasteworks.com> wrote in message

news:uw#vk421CHA.3096@TK2MSFTNGP10...

Simon Wood

unread,
Feb 19, 2003, 6:42:06 AM2/19/03
to
The Dispose bool method is only vaguely releated to GC. It is the
unofficial part of the IDisposble interface (implemented by Control from
which Form derives).

Its basically part of a pattern to release (unmanaged) resources in a
deterministic fashion (unlike Finalize which is not deterministic).

I suspect that on the full framework the forms/controls handler is
calling Dispose() in reponse to WM_CLOSE or WM_DESTROY (it is unlikely
that you are actually seeing GC at this point). The standard
implementation of Dispose() calls Dispose(true) (the significance of the
true is that you are not running in the finalizer thread and so you can
mess with managed objects too). If you are being called from the
finalizer you will be called with Dispose(false).

I would imagine that to save space CF does not do anything in response
to close/destroy.

Don't know if that helps

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Daniel Moth

unread,
Feb 19, 2003, 7:12:25 AM2/19/03
to
Simon

I don't disagree... It is as a result of WM_CLOSE that Dispose gets
called... V Small correction I believe the IDisposable interface is
implemented by Component from which Control derives (from which Form derives
as you pointed out :) Dispose(bool) is just an overload of Component (which
I guess explains your description of it as "unofficial part of IDisposable")

You are also probably right about CF leaving it out for spacesaving but
nevertheless I would like that to be acknowledged by MS and documented as a
difference from the desktop OR acknowledge it as a bug... whichever...

Cheers
Daniel


"Simon Wood" <anon...@devdex.com> wrote in message
news:e4C#uvA2CHA.1728@TK2MSFTNGP12...

Erv Walter

unread,
Feb 19, 2003, 1:12:25 PM2/19/03
to
A related issue that you should be aware of is that in the CF, when
Form.Dispose() is called, the form does not dispose its contained controls
automatically (which does happen on the desktop). If you want this
behavior, you need to add a foreach loop to each form's Dispose override.

"Daniel Moth" <dmo...@hotmail.com> wrote in message

news:#h2Z3BB2...@TK2MSFTNGP11.phx.gbl...

Daniel Moth

unread,
Feb 20, 2003, 7:51:56 AM2/20/03
to
Thanks... I don't think that affects me but it is interesting... Any idea
where this is documented (or post where MS acknowledged)?

Cheers

"Erv Walter" <e...@ewal.net> wrote in message
news:eIEpmJE2CHA.1424@TK2MSFTNGP12...

Erv Walter

unread,
Feb 20, 2003, 10:44:56 AM2/20/03
to
I haven't seen it documented or mentioned by MS. We discovered it while
developing some controls. One of our controls has an unmanaged handle that
needs released, and the control was not getting auto-disposed when we
disposed the form.

I did a little browsing of the CF with ILDASM and I could not find any code
in Control or elsewhere that was disposing the objects in the Controls
container.

"Daniel Moth" <dmo...@hotmail.com> wrote in message

news:#jC4b8N2CHA.1760@TK2MSFTNGP12...

Daniel Moth

unread,
Feb 20, 2003, 11:07:20 AM2/20/03
to
Thanks Erv


"Erv Walter" <e...@ewal.net> wrote in message

news:ObZ4FcP2...@TK2MSFTNGP11.phx.gbl...

Katie Schaeffer [MSFT]

unread,
Feb 20, 2003, 3:34:36 PM2/20/03
to
Hi Folks,

Turns out this is a bug - thank you everyone for bringing this to our
attention.
For .NetCF, once you close a form that was made visible via Visible = true
or Show(), it's dispose function should be called automatically. The
dispose function of it's child controls should also be called
automatically. We currently release the native handles, etc., but the
managed Dispose function doesn't get called (the bug). Note that
currently, if you try to do anything with the form after closing it, you'll
get an ObjectDisposedException because the native window has already been
destroyed.
Also, forms made visible via ShowDialog() are not automatically Disposed
when closed...you can reuse these forms. Their Dispose function should not
be called until the app exits in this case.

Hope this helps clear things up and thanks again for your posts.
-Katie

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Daniel Moth" <dmo...@hotmail.com>
| References: <OI4vcJ$1CHA.2216@TK2MSFTNGP09>
<e4C#uvA2CHA.1728@TK2MSFTNGP12> <#h2Z3BB2...@TK2MSFTNGP11.phx.gbl>
<eIEpmJE2CHA.1424@TK2MSFTNGP12> <#jC4b8N2CHA.1760@TK2MSFTNGP12>
<ObZ4FcP2...@TK2MSFTNGP11.phx.gbl>
| Subject: Re: Form.Dispose
| Date: Thu, 20 Feb 2003 16:07:20 -0000
| Lines: 110
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
| Message-ID: <ebGH0pP2...@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 194.242.149.2
| Path: cpmsftngxa06!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06
microsoft.public.dotnet.framework.compactframework:17205
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

0 new messages