title: Force garbage collection of arrays, C#
body: <p>I have a problem where a couple 3 dimensional arrays allocate a huge amount of memory and the program sometimes needs to replace them with bigger/smaller ones and throws an OutOfMemoryException.</p>
  
  <p>Example: there are 5 allocated 96MB arrays (200x200x200, 12 bytes of data in each entry) and the program needs to replace them with 210x210x210 (111MB). It does it in a manner similar to this:</p>
  
  <pre><code>array1 = new Vector3[210,210,210];
  </code></pre>
  
  <p>Where array1-array5 are the same fields used previously. This should set the old arrays as candidates for garbage collection but seemingly the GC does not act quickly enough and leaves the old arrays allocated before allocating the new ones - which causes the OOM - whereas if they where freed before the new allocations the space should be enough.</p>
  
  <p>What I'm looking for is a way to do something like this:</p>
  
  <pre><code>GC.Collect(array1) // this would set the reference to null and free the memory
  array1 = new Vector3[210,210,210];
  </code></pre>
  
  <p>I'm not sure if a full garbage collecion would be a good idea since that code may (in some situations) need to be executed fairly often.</p>
  
  <p>Is there a proper way of doing this?</p>