title: Possible reasons for FileStream.Write() to throw an OutOfMemoryException?
body: <p>I have 10 threads writing thousands of small buffers (16-30 bytes each) to a huge file in random positions. Some of the threads throw OutOfMemoryException on FileStream.Write() opreation. </p>
  
  <p>What is causing the OutOfMemoryException ? What to look for?</p>
  
  <p>I'm using the FileStream like this (for every written item - this code runs from 10 different threads):</p>
  
  <pre><code>using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite, BigBufferSizeInBytes, FileOptions.SequentialScan))
  {
   ...
   fs.Write();
  }
  </code></pre>
  
  <p>I suspect that all the buffers allocated inside the FileStream don't get released in time by the GC. What I don't understand is why the CLR, instead of throwing, doesn't just run a GC cycle and free up all the unused buffers?</p>