I have been asking myself for quite a while, when exactly objects and variables go out of scope and are garbage collected. Also what the difference between reference and value types is in this regard.
For example if I use
Private Sub Foo()
Dim ob as Integer = 1
End Sub
it is my understanding that the variable goes out of scope when the Sub has run its course and the related memory is freed again. I thought that this was the same with references. However I can do the following
Private Sub Foo()
Dim frm1 as New Form1
frm1.Show() 'Edit made here!
End Sub
and the related form is opened stays open even though the sub is over immediately. Therefore there seem to be references that are kept open somehow, so the new form instance is not disposed of. Maybe there is something special about forms. But what about some other random object?
Private Sub Foo()
Dim ob as New MyRandomClass
End Sub
Will this object persist like the form or is it disposed?
Could someone shed some light about the details of scope and the differences between variables, objects and maybe Forms (which are not really straightforward in VB.net compared to C# in my opinion).