title: Can and will C# write objects to the pagefile?
body: <p>I was wondering if it is possible for C# to write objects to the pagefile.</p>
  
  <p>I already know that a virtual machine for a .NET application is limited to allow one object to only use up 2 GB of ram and will run out of Memory long before that - even on 64-bit version of Windows.</p>
  
  <p>However I need to be able to load a huge amount of strings (not 1 big one but many small ones) and was wondering if it is possible to load them and let them be written to the swap space until they are needed again (unfortunately it is not possible for me to prevent the loading of all the strings because it is forced by an application calling the code I am working on).</p>
  
  <p>To prototype it I tried out to see if the following program will run out of memory as well (which it will), even though it does not try to allocate one huge string:</p>
  
  <pre><code>public static void Main()
  {
          ICollection&lt;StringBuilder&gt; builders = new LinkedList&lt;StringBuilder&gt;();
          double used_ram = 2*1024*1024*1024L;
          int blocksize = 12800000;
          int blocks = (int) (used_ram/blocksize);
          for (int i = 1; i &lt; blocks ; i++)
          {
              StringBuilder sb = new StringBuilder(blocksize/2);
              builders.Add(sb);
          }
          Console.ReadLine();
  }
  </code></pre>
  
  <p>I was hoping that the strings would be written to the swap space and was wondering if there is any way I can force the application to do just that.</p>
  
  <p>EDIT: Changed the use of swap file to pagefile (thanks for the clarifications).</p>
  
  <p>Ok so to enhance my question: if the only limitation of the runtime is that ONE object can not allocate more than 2 gb of memory - why is the above code running out of memory - because the list goes over the 2 gb of memory by holding reference to all the string builders?</p>