Alright, i am still not sure when I should implement garbage-collection in VB. They've made it insanely difficult and blurry, and after two weeks of attempting to figure out when to implement dispose, I am worn out. I have my own classes, but they contain standard classes, such as Integer, String, etc. One of them contains other classes of my own design however, and I don't have a clue how to tell if I need to free them somehow.
Public Class systemClass
Private uppermemBool As Boolean
Private expandedBool As Boolean
Private extendedBool As Boolean
Private memoryShort As Short
Private cpuShort As Short
Private cyclesInt As Integer
Public Class gameClass
Private initializedBool As Boolean
Private systemObject As systemClass
Private videoObject As videoClass
Private soundObject As soundClass
In the example above, the second class uses an instance of the first class, but the first class only contains built-in classes. My main form creates an instance of the second class, then class an initialization function that allows that class to create instances of the three custom classes inside it.
At this point if the program exits, I simply set the second class to "Nothing", but does that free everything? How about a simple call to "free" like every other language out there? I also can't find info on implementing a destructor in VB, which is confusing as heck because you have to have a constructor!
Public Class mainForm
Private gameObject As gameClass
Private Sub mainForm_Load(...) Handles ...
Me.gameObject = New gameClass
Public Sub exitButton_Click(...) Handles ...
Me.gameObject = Nothing 'Does this free it like free() in C?
So is this freeing everything, or should I write a method in the gameClass object that I can call to set the three custom classes in it to "Nothing" before closing? This is just a huge gray area right now and I just need to know how and when to use dispose, or how to write a destructor.
Oh, and what happens if the program closes in another way, such as the user clicking the X in the upper-right of the window? My code wouldn't even set the gameObject to "Nothing"!