title: Serializing an object using Json.Net causes Out of Memory exception
body: <p>Disclaimer: I did went through most of the solution provided here but most of them were talking about OOM exception while Deserialization.</p>
  
  <p>I am trying to serialize an object( it's a Tree) into Json using Json.Net. Everything works fine for small objects but i get OOM exception when i try it with large objects. As it works with smaller object of same datatype i am assuming there is no circular reference (I did inspect my data structure for it). <strong>Is there a way where i can convert my object into stream ( this is a Windows Store app ) and generate the Json using that stream ?</strong></p>
  
  <pre><code> public static async Task&lt;bool&gt; SerializeIntoJson&lt;T&gt;(string fileName, StorageFolder destinationFolder, Content content)
      {
          ITraceWriter traceWriter = new MemoryTraceWriter();
          try
          {
  
              string jsonString = JsonConvert.SerializeObject(content, Formatting.Indented, new JsonSerializerSettings
              {
                  PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                  TypeNameHandling = TypeNameHandling.All,
                  Error = ReportJsonErrors,
                  TraceWriter = traceWriter,
                  StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
              });
              System.Diagnostics.Debug.WriteLine(traceWriter);
  
              StorageFile file = await destinationFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
              await Windows.Storage.FileIO.WriteTextAsync(file, jsonString);
              return true;
          }
          catch (NullReferenceException nullException)
          {
              System.Diagnostics.Debug.WriteLine(traceWriter);
              logger.LogError("Exception happened while serializing input object, Error: " + nullException.Message);
              return false;
          }
          catch (Exception e)
          {
              System.Diagnostics.Debug.WriteLine(traceWriter);
              logger.LogError("Exception happened while serializing input object, Error: " + e.Message, e.ToString());
              return false;
          }
      }
  </code></pre>
  
  <p>In order to convert my object into stream, the code i found out was using a BinaryFormatter which is not available in Windows store app dll's. </p>