treeview in windowsdialog

  • Thread starter Thread starter Co
  • Start date Start date
Martin,

Armin wrote it so nice.

As extra: a ShowDialog form is nothing more then an old Dialog and therefore
it has unmanaged resources.

Before it goes out of scope it is clever to do use its dispose method to
release the unmanaged resources.

That dispose method is implemented by the class where the Form derives from:
the component class.

Unmanaged resources have nothing to do with the managed objects.

A managed object can use (that becomes with all new thing every time less)
an unmanaged resource.

Therefore Yes it is wise to use the form.dispose (unmanaged resources
method) as you have created that form new in your form and it will be go out
of scope.

Cor
 
Martin said:
Sorry this is how my example should have looked...

Sub Test()
dim d as frm = new dlgForm
d.ShowDialog
debug.print (d.SomeMethod)
End Sub


Cor already wrote, though:
Yes, the variable dies as soon as the sub is left. As it held the only
reference to the Form, the GC _can_ collect the object (= the Form) from now
on, but you don't know when it happens. Til then, all ressources (managed
and unmanaged) occupied by the Form are still reserved. As it is considered
good programming style to release ressources ASAP, you can improve the
situation by bringing the release of the unmanaged ressources forward.
That's done by calling Dispose immediatelly after you don't need the Form
anymore.

Sub Test()
dim d as new dlgForm
d.ShowDialog
debug.print (d.SomeMethod)
d.Dispose
End Sub


Armin
 
Martin said:
Sorry this is how my example should have looked...

Sub Test()
dim d as frm = new dlgForm
d.ShowDialog
debug.print (d.SomeMethod)
End Sub


Cor already wrote, though:
Yes, the variable dies as soon as the sub is left. As it held the only
reference to the Form, the GC _can_ collect the object (= the Form) from now
on, but you don't know when it happens. Til then, all ressources (managed
and unmanaged) occupied by the Form are still reserved. As it is considered
good programming style to release ressources ASAP, you can improve the
situation by bringing the release of the unmanaged ressources forward.
That's done by calling Dispose immediatelly after you don't need the Form
anymore.

Sub Test()
dim d as new dlgForm
d.ShowDialog
debug.print (d.SomeMethod)
d.Dispose
End Sub


Armin
 
Back
Top