title: AviSynth Out of Memory Error (100s of image overlays)
body: <p>I want to overlay multiple images on my video at different times. I have user function defined as </p>
  
  <pre><code>function myFunction(clip c, int coordinateX, int from, int to) {
      c = c.trim(0, from-1) + c.trim(from, to).Overlay(myImage, x=coordinateX, y=667, mask=myImageMask, opacity=1) + c.trim(to+1, 0)
      return c
  }
  </code></pre>
  
  <p>which essentially takes <code>myImage</code> image and place it on specific part of the clip.</p>
  
  <p>I call my function as</p>
  
  <pre><code>video = video.myFunction(320, 1, 187)
  </code></pre>
  
  <p>and I have bunch of those like this (I'm trying to make some sort of animation with multiple images)</p>
  
  <pre><code>video = video.myFunction(320, 1, 187)
  video = video.myFunction(480, 1, 187)
  video = video.myFunction(640, 1, 187)
  video = video.myFunction(320, 187, 374)
  video = video.myFunction(480, 187, 374)
  video = video.myFunction(640, 187, 374)
  video = video.myFunction(319, 374, 561)
  </code></pre>
  
  <p>and everything works fine if there is less than ~400 of those calls. If I exceed that limit, "Out of Memory" occurs (I'm using VirtualDub).</p>
  
  <p><img src="https://i.stack.imgur.com/IFlro.png" alt="AviSynth VirtualDub Out of Memory Error"></p>
  
  <p>I suppose it's because AviSynth must process all the calls to figure out the output (although <strong>only ~3 of those 100s</strong> of calls are related to <strong>specific single frame</strong>). If I however remove <code>video =</code> at the beginning of the line, I could have 10000 of those and there is no "Out of Memory" error but of course I don't have video out.</p>
  
  <p>Is there a fix to this? Hundreds/thousands of image overlays at different times on the video clip?</p>