treeview in windowsdialog

  • Thread starter Thread starter Co
  • Start date Start date
You can make your own dialog form.

It is simple a form that is called with showform
And for which the dispose method has to be called as it comes back, because
a dialog is used

Cor
 
You can make your own dialog form.

It is simple a form that is called with showform
And for which the dispose method has to be called as it comes back, because
a dialog is used

Cor
 
You can make your own dialog form.

It is simple a form that is called with showform
And for which the dispose method has to be called as it comes back, because
a dialog is used

Cor

Cor,

I was already started creating such a form with a Treeview on it.
I call it as showDialog.
What do you mean witrh the Dispose.
Should the form be Disposed when it is closed???

Marco
 
You can make your own dialog form.

It is simple a form that is called with showform
And for which the dispose method has to be called as it comes back, because
a dialog is used

Cor

Cor,

I was already started creating such a form with a Treeview on it.
I call it as showDialog.
What do you mean witrh the Dispose.
Should the form be Disposed when it is closed???

Marco
 
Marco,

\\
dim x as new formX
if x.ShowDialog = Dialog.OK then
'Do your things
end if
x.Dispose
//
That text Dialog is probably something else I never know that from my head
because it comes with intelligence.

Cor
 
Marco,

\\
dim x as new formX
if x.ShowDialog = Dialog.OK then
'Do your things
end if
x.Dispose
//
That text Dialog is probably something else I never know that from my head
because it comes with intelligence.

Cor
 
x.Dispose

Is a dialog form not automatically garbage collected when it goes out of
scope then?

Martin
 
x.Dispose

Is a dialog form not automatically garbage collected when it goes out of
scope then?

Martin
 
Martin said:
Is a dialog form not automatically garbage collected when it goes out
of scope then?


Depends on what you mean with "go out of scope". Out of scope for the
application in the sense of the object not being accessible anymore? Or out
of scope in the sense of variables that are not accessible at the current
location? If it's the former, you are partially right, i.e. it can be
collected but it's not necessarily collected as soon as it is not accessible
anymore. That can happen later.

That was about garbage collection. It only collects/destroys _managed_
ressources. Disposing ressources is something different. It's an additional
pattern that enables us to release _unmanaged_ ressource before the GC
destroys the managed ressources that again release unmanaged ressources.

A Form's Dispose method is called automatically whenever the Form is closed
only if it's not a dialog Form (displayed using ShowDialog). This is because
you must have the chance to get the information from the controls (including
related unmanaged ressources) on the dialog Form. Therefore, you must
manually call Dispose afterwards.


Armin
 
Martin said:
Is a dialog form not automatically garbage collected when it goes out
of scope then?


Depends on what you mean with "go out of scope". Out of scope for the
application in the sense of the object not being accessible anymore? Or out
of scope in the sense of variables that are not accessible at the current
location? If it's the former, you are partially right, i.e. it can be
collected but it's not necessarily collected as soon as it is not accessible
anymore. That can happen later.

That was about garbage collection. It only collects/destroys _managed_
ressources. Disposing ressources is something different. It's an additional
pattern that enables us to release _unmanaged_ ressource before the GC
destroys the managed ressources that again release unmanaged ressources.

A Form's Dispose method is called automatically whenever the Form is closed
only if it's not a dialog Form (displayed using ShowDialog). This is because
you must have the chance to get the information from the controls (including
related unmanaged ressources) on the dialog Form. Therefore, you must
manually call Dispose afterwards.


Armin
 
Cor said:
Armin,

Nice text, I assume that it is right that I use it in future?

Cor

LOL Do with it whatever you want and put your signature underneath. ;-)

(I was more expecting comments like this and that is not completeley
correct. (not in particular from you but in general))


Armin
 
Cor said:
Armin,

Nice text, I assume that it is right that I use it in future?

Cor

LOL Do with it whatever you want and put your signature underneath. ;-)

(I was more expecting comments like this and that is not completeley
correct. (not in particular from you but in general))


Armin
 
So taking this scenario where 'Sub Test' is called multiple times do I need
to call dispose on the dialog to avoid wasting resources or will they be
freed automatically when needed?

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

My understanding was that after the sub was exited the instance of the
dlgForm I created would be 'out of scope' and therefore eligable for garbage
collection. If this is wrong then I need to re-think my approach.

Martin.
 
So taking this scenario where 'Sub Test' is called multiple times do I need
to call dispose on the dialog to avoid wasting resources or will they be
freed automatically when needed?

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

My understanding was that after the sub was exited the instance of the
dlgForm I created would be 'out of scope' and therefore eligable for garbage
collection. If this is wrong then I need to re-think my approach.

Martin.
 
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
 
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
 
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
 
Back
Top