unloading forms

G

Glenn

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
 
L

Larry Serflaten

Glenn said:
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
 
G

Glenn

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
 

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