Hi All
Today I learned about the wonderful Reference Types. Hip Hip Huraay ;-)
Good to remember is that Reference Types contain pointers to data stored on the Heap, where Value Types contain their data directly stored on the Stack.
Reference Types are cleaned up by the Garbage Collection, so everything you put in them is by definition garbage ??? Just kidding.
This lesson gave me some good practices and will probably be and eye-opener for many developers when the String and StringBuilder topic is adressed.
After today, I will NEVER concatenate strings again, without using the StringBuider.
We all did (or do) something like this at least ones in our development carreer:
dim a as String = "This "
dim b as String = a & "Is "
dim c as String = b & "a "
dim d as String = c & "test!"
What you most likely didn't know is that the runtime creates 4 variables of String on the Heap and only keeps a reference to the last one. The other 3 have to be cleaned up by, oh yess, the Garbage Collection.
Imagine the performance cost when you concatenate words that span over many lines into a single string. Gulp!
Hail to the StringBuilder class.
In addition to this usefull info, some basic must-knows came across in this lesson. Like Exceptions and Arrays.
Next lesson is all about Creating Classes. Can't wait for that one ;-)
Dim sb as New StringBuilder()
sb.Append("Be")
sb.Append(" seeing")
sb.Append(" ya !")
MessageBox.Show(sb.ToString())
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment