title: MediaComposition.RenderToFileAsync crashes with many static images
body: <p>I have a Windows Phone 8.1 Silverlight app that renders .gif files to .mp4, using the Windows.Media.Editing.MediaComposition class. </p>
  
  <p>Certain files will randomly crash the RenderToFileAsync method. There are at least two different error messages you can receive, one stating insufficient memory.</p>
  
  <p>Does anyone have any ideas for a workaround, or some insider knowledge on how this is supposed to work?</p>
  
  <p>Repro:</p>
  
  <ul>
  <li>Create new c# WP8.1 Silverlight app blank project in VS2013</li>
  <li>Add Usings and OnNavigatedTo to MainPage.xaml.cs as below.</li>
  <li><p>Run in 512MB emulator. Observe crash (most of the time). Fiddle with value of i to see it work properly.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Navigation;
  using Microsoft.Phone.Controls;
  using Microsoft.Phone.Shell;
  using System.Windows.Media.Imaging;
  using System.IO;
  using Windows.Media.Editing;
  using System.Diagnostics;
  </code></pre></li>
  </ul>
  
  <p>-</p>
  
  <pre><code>    protected async override void OnNavigatedTo(NavigationEventArgs e)
      {
      base.OnNavigatedTo(e);
      SystemTray.ProgressIndicator = new ProgressIndicator();
      SystemTray.ProgressIndicator.IsVisible = true;
      SystemTray.ProgressIndicator.IsIndeterminate= true;
      var comp = new MediaComposition();
      var r = new Random();
  
      for (int i = 0; i &lt; 190; i++)
      {
          var wb = new WriteableBitmap(576, 300);
  
          for (int iPix = 0; iPix &lt; wb.Pixels.Length; iPix++)
          {
              wb.Pixels[iPix] = r.Next();
          }
  
          string filename = "file" + i.ToString() + ".jpg";
          var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);
          using (var curr = await file.OpenStreamForWriteAsync())
          {
              wb.SaveJpeg(curr, wb.PixelWidth, wb.PixelHeight, 0, 95);
          }
  
          var clip = await MediaClip.CreateFromImageFileAsync(file, TimeSpan.FromMilliseconds(60));
          comp.Clips.Add(clip);
      }
  
      // Ensure add capability to write to video library AND ID_CAP_MEDIALIB_PHOTO and change below to 
      // Windows.Storage.KnownFolders.VideosLibrary to see output in Videos app
      var destFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
      var destFile = await destFolder.CreateFileAsync("test.mp4", Windows.Storage.CreationCollisionOption.ReplaceExisting);
  
      Debug.WriteLine("Mem use before render to disk: " + Windows.System.MemoryManager.AppMemoryUsage.ToString("N0"));
      await comp.RenderToFileAsync(destFile);
      Debug.WriteLine("Mem use after render to disk: " + Windows.System.MemoryManager.AppMemoryUsage.ToString("N0"));
  
      SystemTray.ProgressIndicator.IsVisible = false; 
      MessageBox.Show("Done OK");
  
      }
  </code></pre>