Should I set variables to nothing and erase arrays when I'm done with them? Even when the program is shutting down??
Printable View
Should I set variables to nothing and erase arrays when I'm done with them? Even when the program is shutting down??
My understanding is that anything you create with the New keyword should be set to Nothing when you're done with it. So, if you Dim something As New ... or set something = New ..., in a routine, you should set something = Nothing before exiting the routine.
However, VB seems to clean itself up pretty well. It would probably be good practice to always initialize things when done with them, if you ever had to go to C++.
I've only once seen one of my programs app error (dr. watson) while it was still running when a treeview node which was previously referenced in an object I created was removed. The object had no where to point to anymore and sucked the life out of my program when it got referenced once more.
Ask someone who programs in C++ this question.
So in other words...All Arrays will be cleared anyways on program shutdown?
I think for a fixed-size array, they're automatically taken care of.
For dynamic arrays though, it's good idea to clean those up at the end of a function
VB Code:
delete myarray
It's especially good if you're using arrays alot, because VB is limited on memory, you can't allocate it on the fly like C++. I think...I haven't done VB in forever.
And it's good to set string to zero-length also.
VB Code:
mystring=""