Dispose(bool) not getting called


C

C Enright

I have a large .net cf application. When the application
is hidden and many other apps are opened, it appears that
the clr is disposing some of the forms in my app. I say
this because I an ObjectDisposedException is thrown when
accessing the form. Anyway, while I understand the clr
is probably trying to free up memory in response to the
os asking it to, why would it dispose my forms? To top
it off, even if I override the 'protected override void
Dispose(bool disposing)' method, it never gets called.

Anybody have any clues?
 
Ad

Advertisements

C

Chris Theorin

Or how 'bout this... why doesn't the CF automatically call Dispose on the
Controls in the Form.Controls collection when the Form is Disposed (outside
of the finalizer)?
 
C

C Enright

Chris:

I even tried calling the public non-virtual Dispose() in
Windows.Forms.Control on a Form class myself and it does
not call the overriden function Dispose(bool)....


You gave me an idea. I created a control:

public class Mycontrol : Control
{
protected override void Dispose(bool disposing)
{
MessageBox.Show("Disposing");
base.Dispose (disposing);
}

~Mycontrol()
{
MessageBox.Show("Finalizer");
}

}

and inserted it into Form.Controls and called Dispose on
the form and the "Disposing" message is never
displayed... However, upon finalization, the "Finalizer"
message is displayed and in the debugger it looks like
the control has been disposed...

So I propose the implementation of the non-virtual Dispose
() method in System.Windows.Forms.Control and its
finalizer never call the virtual Dispose(bool) function.

If this is the case, I would assume it to be a bug.

Also, does anybody know anything about the common
language runtime disposing forms on it's own?
 
C

Chris Theorin

and inserted it into Form.Controls and called Dispose on
the form and the "Disposing" message is never
displayed... However, upon finalization, the "Finalizer"
message is displayed and in the debugger it looks like
the control has been disposed...

This is what I was trying to say in my post... different from how the full
..NET framework does things huh ("Finalizer" displays even if you just create
'MyControl' without putting in the Controls collection).
Also, does anybody know anything about the common
language runtime disposing forms on it's own?

On the "head" form in my application, I call this.Dispose() in the
Form_Closing event and then "fix" the defualt Dispose(disposing) override to
loop through the Controls collection, calling Dispose() on each before
calling base.Dispose(disposing).
 
Ad

Advertisements

A

Armin Sadeghi [MSFT]

The compact framework does not dispose controls (including form) until the
app domain terminates. The CLR itself should not be disposing individual
forms, however the PocketPC OS will terminate apps in the background when
necessary to reclaim resources.

-Armin

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Chris Theorin" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Dispose(bool) not getting called
| Date: Fri, 11 Jul 2003 09:24:07 -0500
| Lines: 90
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: outbound.epicsys.com 12.148.194.126
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:27997
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| > and inserted it into Form.Controls and called Dispose on
| > the form and the "Disposing" message is never
| > displayed... However, upon finalization, the "Finalizer"
| > message is displayed and in the debugger it looks like
| > the control has been disposed...
|
| This is what I was trying to say in my post... different from how the full
| .NET framework does things huh ("Finalizer" displays even if you just
create
| 'MyControl' without putting in the Controls collection).
|
| > Also, does anybody know anything about the common
| > language runtime disposing forms on it's own?
|
| On the "head" form in my application, I call this.Dispose() in the
| Form_Closing event and then "fix" the defualt Dispose(disposing) override
to
| loop through the Controls collection, calling Dispose() on each before
| calling base.Dispose(disposing).
|
| | > Chris:
| >
| > I even tried calling the public non-virtual Dispose() in
| > Windows.Forms.Control on a Form class myself and it does
| > not call the overriden function Dispose(bool)....
| >
| >
| > You gave me an idea. I created a control:
| >
| > public class Mycontrol : Control
| > {
| > protected override void Dispose(bool disposing)
| > {
| > MessageBox.Show("Disposing");
| > base.Dispose (disposing);
| > }
| >
| > ~Mycontrol()
| > {
| > MessageBox.Show("Finalizer");
| > }
| >
| > }
| >
| > and inserted it into Form.Controls and called Dispose on
| > the form and the "Disposing" message is never
| > displayed... However, upon finalization, the "Finalizer"
| > message is displayed and in the debugger it looks like
| > the control has been disposed...
| >
| > So I propose the implementation of the non-virtual Dispose
| > () method in System.Windows.Forms.Control and its
| > finalizer never call the virtual Dispose(bool) function.
| >
| > If this is the case, I would assume it to be a bug.
| >
| > Also, does anybody know anything about the common
| > language runtime disposing forms on it's own?
| >
| >
| > >-----Original Message-----
| > >Or how 'bout this... why doesn't the CF automatically
| > call Dispose on the
| > >Controls in the Form.Controls collection when the Form
| > is Disposed (outside
| > >of the finalizer)?
| > >
| > >| > >> I have a large .net cf application. When the
| > application
| > >> is hidden and many other apps are opened, it appears
| > that
| > >> the clr is disposing some of the forms in my app. I say
| > >> this because I an ObjectDisposedException is thrown
| > when
| > >> accessing the form. Anyway, while I understand the clr
| > >> is probably trying to free up memory in response to the
| > >> os asking it to, why would it dispose my forms? To top
| > >> it off, even if I override the 'protected override void
| > >> Dispose(bool disposing)' method, it never gets called.
| > >>
| > >> Anybody have any clues?
| > >>
| > >
| > >
| > >.
| > >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top