title: VB.NET: If I pass a String ByVal into a function but do not change the string, do I have one or two strings in memory?
body: <p>I know strings are immutable, so the minute you change a string reference's value .NET makes a brand new string on the heap.  </p>
  
  <p>But what if you don't <em>change</em> the value of a string reference; rather, you simply pass it into a function <strong><code>ByVal</code></strong> -- does this operation copy the string value on the heap as well?  My inclination is "no," but I'd like to confirm.</p>
  
  <p>For example:</p>
  
  <pre><code>Public Function IsStringHello(ByVal test As String) As Boolean 
    Return (String.Compare(test, "Hello") = 0)    
  End Function
  </code></pre>
  
  <p>Calling program:</p>
  
  <pre><code>Dim myWord as String = "Blah"
  Dim matchesHello as Boolean = IsStringHello(myWord)
  </code></pre>
  
  <p>I know passing <code>myWord</code> by value makes a copy of the <strong>reference</strong> to "Blah", but since I have not tried to change the string itself, would it make another copy of the string on the heap?</p>