title: OutOfMemoryException in ProtoBuf-Net Serialization
body: <p>I serialize some big <code>Dictionary</code> to disk by protobuf-net, and the size of the file on disk is 450MB.</p>
  
  <p>Often, the code failed with OutOfMemoryException </p>
  
  <pre><code>System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
     at ProtoBuf.BufferPool.ResizeAndFlushLeft(Byte[]&amp; buffer, Int32 toFitAtLeastBytes, Int32 copyFromIndex, Int32 copyBytes) in c:\Dev\protobuf-net\protobuf-net\BufferPool.cs:line 60
     at ProtoBuf.ProtoWriter.StartSubItem(Object instance, ProtoWriter writer, Boolean allowFixed) in c:\Dev\protobuf-net\protobuf-net\ProtoWriter.cs:line 341
     at ProtoBuf.ProtoWriter.WriteObject(Object value, Int32 key, ProtoWriter writer) in c:\Dev\protobuf-net\protobuf-net\ProtoWriter.cs:line 44
     at proto_15(Object , ProtoWriter )
     at ProtoBuf.ProtoWriter.WriteObject(Object value, Int32 key, ProtoWriter writer, PrefixStyle style, Int32 fieldNumber) in c:\Dev\protobuf-net\protobuf-net\ProtoWriter.cs:line 116
     at ProtoBuf.Meta.TypeModel.SerializeWithLengthPrefix(Stream dest, Object value, Type type, PrefixStyle style, Int32 fieldNumber, SerializationContext context) in c:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 548
     at ProtoBuf.Meta.TypeModel.SerializeWithLengthPrefix(Stream dest, Object value, Type type, PrefixStyle style, Int32 fieldNumber) in c:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 515
     at ProtoBuf.Serializer.SerializeWithLengthPrefix[T](Stream destination, T instance, PrefixStyle style, Int32 fieldNumber) in c:\Dev\protobuf-net\protobuf-net\Serializer.cs:line 352
  </code></pre>
  
  <p>The machine has 20GB+ free memory. 
  <img src="https://i.stack.imgur.com/GToAW.png" alt="enter image description here"></p>
  
  <p>And my process only takes up 4.6GB
  <img src="https://i.stack.imgur.com/yYpMl.png" alt="enter image description here"></p>
  
  <p>And the app.config is tuned for big memory</p>
  
  <pre><code>&lt;runtime&gt;
      &lt;gcAllowVeryLargeObjects enabled="true" /&gt;
      &lt;gcServer enabled="true"/&gt;
  &lt;/runtime&gt;
  </code></pre>
  
  <p>Currently I use a <code>try-catch</code> to catch the exception and re-try after several seconds. And they usually works.</p>
  
  <p>Is there a way to avoid this exception?</p>