title: c# string interning
body: <p>I am trying to understand string interning and why is doesn't seem to work in my example. The point of the example is to show Example 1 uses less (a lot less memory) as it should only have 10 strings in memory. However, in the code below both example use roughly the same amount of memory (virtual size and working set).</p>
  
  <p>Please advice why example 1 isn't using a lot less memory? Thanks</p>
  
  <p>Example 1:</p>
  
  <pre><code>        IList&lt;string&gt; list = new List&lt;string&gt;(10000);
  
          for (int i = 0; i &lt; 10000; i++)
          {
              for (int k = 0; k &lt; 10; k++)
              {
                  list.Add(string.Intern(k.ToString()));
              }
  
          }
  
          Console.WriteLine("intern Done");
          Console.ReadLine();
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>        IList&lt;string&gt; list = new List&lt;string&gt;(10000);
  
          for (int i = 0; i &lt; 10000; i++)
          {
              for (int k = 0; k &lt; 10; k++)
              {
                  list.Add(k.ToString());
              }
  
          }
  
          Console.WriteLine("intern Done");
          Console.ReadLine();
  </code></pre>