Out of memory problems

  • Thread starter Thread starter jayderk
  • Start date Start date
J

jayderk

I have an application that goes back and forth between forms alot over the
course of a day and appears to have a memory leak like situation as I can go
to the form about 35 time and with 15208K of ram, it seems to be adding a
few more K every time or few times I open up a new one. I read some threads
explaining going between forms should be done in a create once use many
fashion. my problem with this is it is not very clean, once we are done with
a resource and not going to use it for a few hours possibly we should
release it back to the system. I have found a very clean way ( i think ) to
do this.

frmView frmViewR = new frmView();

frmViewR.ShowDialog();

frmViewR.Dispose();

frmViewR = null;



the memory seems to be alot more stable doing this..

can you guys see any major problems with this?
 
Actually your workaround is a correct way to dispose of the modal form.
Modal forms are not disposed of automatically. Modeless from are disposed of
when closed
 
Well I am dang glad I tried that then...
that one should be in the FAQ ... cause I looked allllll over and this is
the first time I have heard this...

thanks again...
Jay
 
just one more thing....
we do not need to dispose the messagebox? it is not model but.... I want to
make sure..

thanks, Jay
 
ouch.. that sounds like a zing.... I didn't think I would have to dispose a
modal dialog when I have seen a modal-less dialog box perform great.

regards,
Jay
 
Chris Theorin said:
Alex, is your statement "Modal forms are not disposed of automatically"
correct?

Afraid, yes. The modeless from displayed via Form.Show will close when you
click on OK button and dispose (including all child controls). If you do not
want it to dispose, the MinimizeBox property should be set to false, causing
Ok button to be replaced with X

Modal form will close but persist in memory, so that it can be reused by
calling ShowDialog over and over - until you explicitly dispose of it. I
believe, that the implementation details are such, that GC will not collect
it even if you release the reference by either going out of scope or setting
var to null. Because of this it'll have to be disposed explicitly.
It seems to me that the best thing would be to wrap a C# 'using' statement
around all forms you create and show modally... if only that bug didn't
exist in the CF (: P

Yes, agree 100%
 
<WowImReallySorryJayderk>Damn!</WowImReallySorryJayderk>

Alex Feinman said:
Afraid, yes. The modeless from displayed via Form.Show will close when you
click on OK button and dispose (including all child controls). If you do not
want it to dispose, the MinimizeBox property should be set to false, causing
Ok button to be replaced with X

Wait a minute (yes, kind of afraid (would be much more afraid if I didn't
always show forms modally and dispose them explicitly when done)), I put a
MessageBox.Show("Goodbye: " + disposing.ToString()) in the Dispose(bool
disposing) method of the Form I show (non-modally) with the MinimizeBox
property set to false, and no matter whether I use the 'OK' button or call
this.Close() in a Button event handler, I never see the 'Goodbye: xxx'
message, but I never get the OutOfMemoryException I do if showing the form
modally withough disposing...
Modal form will close but persist in memory, so that it can be reused by
calling ShowDialog over and over - until you explicitly dispose of it. I
believe, that the implementation details are such, that GC will not collect
it even if you release the reference by either going out of scope or setting
var to null. Because of this it'll have to be disposed explicitly.

I confirmed this to be true, releasing the reference won't cut it.
 
The bug that Dispose() is not called on Controls when they are destroyed is
not fixed in any released versions of the .NET Compact Framework. However,
all native resources attached to the control are cleaned up.

David Wrighton
NET Compact Framework

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]>
<[email protected]>
<[email protected]>
<#[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Out of memory problems
| Date: Tue, 26 Aug 2003 21:06:58 -0500
| Lines: 28
| 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!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:32101
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| I installed the SP1 cab file 'netcf.all.wce4.X86.cab' on the Pocket PC
2003
| emulator and I still don't ever see my MessageBox showing up...
|
| MSFT: was this not fixed in SP1?
|
| | > | > >
| > > Wait a minute (yes, kind of afraid (would be much more afraid if I
| didn't
| > > always show forms modally and dispose them explicitly when done)), I
put
| a
| > > MessageBox.Show("Goodbye: " + disposing.ToString()) in the
Dispose(bool
| > > disposing) method of the Form I show (non-modally) with the
MinimizeBox
| > > property set to false, and no matter whether I use the 'OK' button or
| call
| > > this.Close() in a Button event handler, I never see the 'Goodbye: xxx'
| > > message, but I never get the OutOfMemoryException I do if showing the
| form
| > > modally withough disposing...
| >
| > I believe that this one was supposed to be fixed in SP1
| >
| >
|
|
|
 
Aha! Thank you, David.

David Wrighton said:
The bug that Dispose() is not called on Controls when they are destroyed is
not fixed in any released versions of the .NET Compact Framework. However,
all native resources attached to the control are cleaned up.

David Wrighton
NET Compact Framework

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
Back
Top