title: "[CALayer renderInContext]" crashes on iPhone X
body: <p>I have a custom <code>UIView</code> that I want to render as an <code>UIImage</code>. The custom <code>UIView</code> is a subclass of <code>UIImageView</code>. </p>
  
  <p>Inside this view, I am rendering some UI elements (drawing a bunch of circles over the image). The number of circles added can go up to the order of thousands.</p>
  
  <p>I am using this simple code snippet to render the view as an <code>UIImage</code>:</p>
  
  <pre><code>// Create the UIImage (code runs on the main thread inside an @autorelease pool)
  UIGraphicsBeginImageContextWithOptions(viewToSave.image.size, viewToSave.opaque, 1.0);
  [viewToSave.layer renderInContext:UIGraphicsGetCurrentContext()];
  imageToSave = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  
  // Since I'm rendering some stuff inside the .layer of the UIView,
  // I don't think I can use "drawViewHierarchyInRect: afterScreenUpdates:"
  </code></pre>
  
  <p>Here is the memory allocations taken from Instruments, in an example with ~3000 circles added as sub-views:</p>
  
  <p><a href="https://i.stack.imgur.com/JHJNE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JHJNE.png" alt="MEMORY ALLOCATIONS (HEAP + ANONYMOUS VM)"></a></p>
  
  <p>Now here's the strange part... This runs fine and I can render the image multiple times (consecutive) and save it in the image gallery on devices like iPhone 5, iPhone 5s, iPhone 6s, iPad Air 2, iPad Mini 4... But the same code triggers a memory warning on <strong>iPhone X</strong> and eventually crashes the application...</p>
  
  <p>Unfortunately, I do not have access to an iPhone X and the person who reported this doesn't have access to a Mac, so I cannot investigate deeper.</p>
  
  <p>I really don't know if I am doing anything wrong... Are you aware if there is something different about the iPhone X? I've been struggling this issue for quite a while... </p>