473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Memory not reclaimed on modeless forms

PGP
Sorry i asked the same question yesterday but did a bad job on describing
the issue so here is a better description.

This is in .NET Compact Framework.

I have a form which creates modeless forms using code like

Form frm = new Form1() ;
frm.Show() ;

These modeless forms get closed and i can see their corresponding Dispose
getting called. It seems that the memory allocated for these forms are never
collected after they are closed. This causes the application to run slower
and slower as more forms are opened and closed.

What do i do to make sure that the memory allocated by these forms are
reclaimed when they are closed?

Thanks in advance.
Aug 18 '06 #1
5 1751
Hi,

"PGP" <priyesh_do_not_replywrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
Sorry i asked the same question yesterday but did a bad job on describing
the issue so here is a better description.

This is in .NET Compact Framework.

I have a form which creates modeless forms using code like

Form frm = new Form1() ;
frm.Show() ;

These modeless forms get closed and i can see their corresponding Dispose
getting called. It seems that the memory allocated for these forms are
never collected after they are closed. This causes the application to run
slower and slower as more forms are opened and closed.
Remember that the GC runs in the background and at a not precise interval so
it's not uncommon to see the memory use to increase.
This in no way would make the app to run slower though.

I think that you may have another problem with the form, what is this form
doing? Do you use any 3rd party component there? Do you keep a reference to
the form (or to any object you create in the form) ina collection outside
the form?

What if you remove ALL the functionality of the forms and just create
/destroy it, do you see the same issue?

Also install the SP1 of the framework
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 18 '06 #2
PGP
Remember that the GC runs in the background and at a not precise interval
so it's not uncommon to see the memory use to increase.
This in no way would make the app to run slower though.

I think that you may have another problem with the form, what is this form
doing? Do you use any 3rd party component there? Do you keep a reference
to the form (or to any object you create in the form) ina collection
outside the form?

What if you remove ALL the functionality of the forms and just create
/destroy it, do you see the same issue?

Also install the SP1 of the framework
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Ignacio.

I created samples to test this scenario. There are no outside collections
refering to the form in question. If the form is created and destroyed in
the same function, memory seems to be steady but finalize is not called on
the form even after a GC.Collect call. I understand there is no need to
force the collect, but this was done just for testing purposes to draw some
conclusions.

If i create a panel in a form, create a sub form and add the sub form to the
panel, then on a button press or something remove the form from the panel's
collection and do a GC.Collect, my finalizers are hit correctly. But if i
close the form using the form's top right close button, dispose is called
but not finalize. In the actual application i am trying to debug, users
close sub forms using the X button.

Aug 18 '06 #3
"PGP" <priyesh_do_not_replywrote in message
news:u1**************@TK2MSFTNGP06.phx.gbl...
Sorry i asked the same question yesterday but did a bad job on describing
These modeless forms get closed and i can see their corresponding Dispose
getting called. It seems that the memory allocated for these forms are
never collected after they are closed. This causes the application to run
slower and slower as more forms are opened and closed.

What do i do to make sure that the memory allocated by these forms are
reclaimed when they are closed?
Years ago I got into the habit of putting

base.Dispose();

in the Closed event of my modeless forms. It has been a long time since I
have investigated this issue, but IIRC this was the only way I could be sure
that Dispose() was called in a timely manner.

The actual situation today may be different than I have described. As I
say, it has been years since I have looked into it, probably 4 years.

-- Alan
Aug 18 '06 #4
Hi,
Ignacio.

I created samples to test this scenario. There are no outside collections
refering to the form in question. If the form is created and destroyed in
the same function, memory seems to be steady but finalize is not called on
the form even after a GC.Collect call. I understand there is no need to
force the collect, but this was done just for testing purposes to draw
some conclusions.
IMO You should let GC run alone, MS has expend a lot of resources to make it
run efficientely, so unless you really know what you are doing and why you
are doing it do not touch it.

I have an application that does run on a PPC for days and shows/destroy
forms on a regular basis and I have no problem at all with the memory.
If i create a panel in a form, create a sub form and add the sub form to
the panel,
what you mean with creating a subform inside the panl ?

Here is where the problem may be.
Why dont just add the controls that currently host the form to the panel
directly?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 18 '06 #5
PGP

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote
in message news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,
>Ignacio.

I created samples to test this scenario. There are no outside collections
refering to the form in question. If the form is created and destroyed in
the same function, memory seems to be steady but finalize is not called
on the form even after a GC.Collect call. I understand there is no need
to force the collect, but this was done just for testing purposes to draw
some conclusions.

IMO You should let GC run alone, MS has expend a lot of resources to make
it run efficientely, so unless you really know what you are doing and why
you are doing it do not touch it.

I have an application that does run on a PPC for days and shows/destroy
forms on a regular basis and I have no problem at all with the memory.
>If i create a panel in a form, create a sub form and add the sub form to
the panel,

what you mean with creating a subform inside the panl ?

Here is where the problem may be.
Why dont just add the controls that currently host the form to the panel
directly?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Ignacio,

In the original issue, there was a toolbar object which held on to a
reference to the modeless form. This toolbar object was alive throughout the
application. Appropriate dispose and ref = null on form closed takes care of
the issue in actual form.

I also had to make sure that the maximizebox = minimizebox = false on the
modeless form so that it will display an "ok" on the top left rather than an
"X". Why do i have to do this? Does the "X" mean that the form will not be
closed ?
Aug 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Ramasubbu Ramasubramanian XR (AS/EAB) | last post by:
What is memory leakage, could any one explain with sample code
0
by: Andrew | last post by:
I get a Null Reference Exception if I close a modeless form (that is, a form displayed using Show()) when a selection is made from a ComboxBox. If the form is modal (displayed using ShowDialog())...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
17
by: David Schwartz | last post by:
Has anyone noticed memory leaks in their VB.NET Windows Forms apps? My app definitely has some memory leaks, so I did a simple test to see if it was my app or something about VB.NET. I created...
2
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. · I need to display a modeless dialog from the main form. o This allows user to continue to work with the...
8
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. I have two projects in my application Project A and Project B. And Project A has the reference of Project B. I...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
11
by: dhtml | last post by:
(originally mis-posted on m.p.s.jscript...) I've just closed all windows in Firefox and its using 244MB of memory. I have no idea why. I had GMail open, a page from unicode, the CLJ FAQ. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.