title: Libav - how to correctly free memory leaking with av_write_frame
body: <p>I am using LIBAV on Ubuntu to save user's video stream(RTP VP8) on server in WebM format.
  The problem is, memory is leaking when using av_write_frame. Memory usage is constantly growing (<strong>equally</strong> with the <strong>webm file size</strong>) and is never freed after finishing the video recording. The only way to free the memory(RAM) is deleting the WebM file from the storage (HD) afterwards.</p>
  
  <p>I have 2 questions:</p>
  
  <ol>
  <li>Is it possible to free the memory consumed by <code>av_write_frame</code> during runtime? I am freeing the <code>packet.data</code> correctly. Memory usage is not growing when <code>av_write_frame</code> line is commented.</li>
  <li><p>What is the correct way to close the file? This is what I'm doing (it does not free the memory):</p>
  
  <p><code>av_write_trailer(fctx);
  avcodec_close(vStream-&gt;codec);
  avio_close(fctx-&gt;pb);
  avformat_free_context(fctx);</code></p></li>
  </ol>