By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

unloading forms

P: n/a
I am confused about when a form is unloaded, if ever. I have forms loading
as MDI forms that have a withevents reference to a global class raising
events. When the forms close, the closed event fires, etc., but the raised
event continues to be captured in the forms. The form is opened from a sub
on the main form, like

Dim frm as frmMine

frm = new frmMine
frm.show

The frm is a local variable to the sub so goes out of scope with the sub.

Why would this continue to fire, and how can I get the form to unload. In
general, I have tested a few sample apps that have simply an MDI that opens
a form and when the form has some databound controls linked to a dataset,
when the form's close the memory use stays the same or even increases:
reopen the form and the memory increases, repeat over and over and the
memory grows. Calling gc.collect has no effect, but if I reduce the form to
hidden and re-open then the memory drops down to very little and when I
re-open the form it remains small. What gives?

Thanks for any help, I am fairly new to .Net.

Glenn
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Glenn,

One way is to call Form.Close to reclaim memory and destroy the form.

http://msdn.microsoft.com/library/de...CloseTopic.asp

HTH
rawCoder

"Glenn" <g.***@comcast.net> wrote in message
news:e3**************@tk2msftngp13.phx.gbl...
I am confused about when a form is unloaded, if ever. I have forms loading
as MDI forms that have a withevents reference to a global class raising
events. When the forms close, the closed event fires, etc., but the raised event continues to be captured in the forms. The form is opened from a sub on the main form, like

Dim frm as frmMine

frm = new frmMine
frm.show

The frm is a local variable to the sub so goes out of scope with the sub.

Why would this continue to fire, and how can I get the form to unload. In
general, I have tested a few sample apps that have simply an MDI that opens a form and when the form has some databound controls linked to a dataset,
when the form's close the memory use stays the same or even increases:
reopen the form and the memory increases, repeat over and over and the
memory grows. Calling gc.collect has no effect, but if I reduce the form to hidden and re-open then the memory drops down to very little and when I
re-open the form it remains small. What gives?

Thanks for any help, I am fairly new to .Net.

Glenn

Nov 21 '05 #2

P: n/a
I no longer have a reference to the form elsewhere to call close: once the
procedure that opened the form ends, its reference that was used to open it
is gone.

The user is closing the form through the X box and the form's closed event
is firing: doesn't this mean the form is closed? However its form level
withevents variable is still receiving events fired elsewhere.

Thanks.

Glenn
"rawCoder" <ra******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Glenn,

One way is to call Form.Close to reclaim memory and destroy the form.

http://msdn.microsoft.com/library/de...CloseTopic.asp
HTH
rawCoder

"Glenn" <g.***@comcast.net> wrote in message
news:e3**************@tk2msftngp13.phx.gbl...
I am confused about when a form is unloaded, if ever. I have forms loading as MDI forms that have a withevents reference to a global class raising
events. When the forms close, the closed event fires, etc., but the raised
event continues to be captured in the forms. The form is opened from a

sub
on the main form, like

Dim frm as frmMine

frm = new frmMine
frm.show

The frm is a local variable to the sub so goes out of scope with the sub.
Why would this continue to fire, and how can I get the form to unload. In general, I have tested a few sample apps that have simply an MDI that

opens
a form and when the form has some databound controls linked to a dataset, when the form's close the memory use stays the same or even increases:
reopen the form and the memory increases, repeat over and over and the
memory grows. Calling gc.collect has no effect, but if I reduce the

form to
hidden and re-open then the memory drops down to very little and when I
re-open the form it remains small. What gives?

Thanks for any help, I am fairly new to .Net.

Glenn


Nov 21 '05 #3

P: n/a

"Glenn" <g.***@comcast.net> wrote in
I am confused about when a form is unloaded, if ever.
You'll need to get familiar with the Garbage Collection model.
Why would this continue to fire, and how can I get the form to unload.


The form isn't unloaded, it is probably waiting for the next garbage
collection sweep. If you want it to release those WithEvents variables,
then you'll have to tell it to do that as it is closing down....

LFS
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.