Does this leak memory?
Dim Public strBldr As New StringBuilder("test", 5)
‘alloc a StringBuilder
MsgBox(strBldr.ToString()) ‘use the StringBuilder
strBldr = New StringBuilder("a", 2)
‘did the destructor of StringBuilder holding “test”
'free up its memory?
As StringBuilder does not implement a Clear() method, and I am having timing issues with the MSDN offered .Length = 0 + .Capacity = 0 solution; the following works fine if I uncomment any of the MsgBox() statements but fails to set retVal.Capacity = 2 elsewise and therefore the retVal.Append fails.
Public Function WhatChar(ByVal CBox As ComboBox, ByRef retVal As StringBuilder) As Integer
WhatChar = CBox.SelectedIndex
retVal.Length = 0
retVal.Capacity = 0
retVal.Capacity = 2
'MsgBox("cb INDEX ")
Select Case CBox.SelectedIndex
Case 0 'single space
retVal.Append(" ")
Case 1 'hyphen
retVal.Append("-")
Case 2 'single space>hyphen<single space>
retVal.Capacity = 4
retVal.Append(" - ")
Case 3 'open single quote
retVal.Append("`")
Case 4 'underscore
retVal.Append("_")
Case Else 'everything else
retVal.Append(CBox.SelectedText)
End Select
'MsgBox("retVal " + retVal.ToString())
End Function
The forum at MSDN has conflicting information. Any thoughts?