title: AVPlayer crashes after multiple usage - iOS
body: <p>I am using an <code>AVPlayer</code> object to stream Ultra HD videos in my app. Its usage is pretty straight forward but I'm having an issue after 5~6 streams.</p>
  
  <h2>The issue</h2>
  
  <p>The app crashes, the debug session is closed, and I have a message on the console:</p>
  
  <blockquote>
    <p>Message from debugger: Terminated due to memory issue</p>
  </blockquote>
  
  <p>This happens every time after watching 4 or 5 videos on an iPhone 6, and 7 or 8 videos on an iPhone 7.</p>
  
  <h2>What I have tried</h2>
  
  <p>Because the debug session ends when my app crashes, I can't see the memory usage exactly when the crash happens. However, before it crashes, the debug session tells me that 2,5% of the RAM is used for the app, even after 4 streams. Not that much!</p>
  
  <p>I recorded my allocations using Instruments and found out that I am never using more than 40MiB which is really not that much.</p>
  
  <h2>My code</h2>
  
  <p>I only store one <code>AVPlayer</code> in my main User Session, so the debug session and the instruments allocations records include the memory for my player from the beginning.</p>
  
  <p>Each time the user exits the player view controller, I only replace the current player item by nil (Swift), like so:</p>
  
  <pre><code>player.replaceCurrentItem(with: nil)
  </code></pre>
  
  <p>And if the user wants to see another video, again, I replace the current item by the new one.</p>
  
  <p>I tried creating one <code>AVPlayer</code> for each video but that didn't change anything.</p>
  
  <h1>Questions</h1>
  
  <p>Does someone have any idea on what's happening?</p>
  
  <p>Is it a good idea to use the <code>AVPlayer</code> to stream 4K videos?</p>
  
  <p>Which player does the Youtube iOS app use?</p>
  
  <p>A lot of VR apps (Jaunt, Within, NYT VR, Sky VR, ...) are streaming 4K videos for virtual reality. Any idea on which player are they using?</p>
  
  <h3>Note</h3>
  
  <p>I am using Swift for this project but feel free to answer in Objective-C if you want!</p>