title: renderincontext Memory Leak if not use on Main thread
body: <p>I am trying to convert my UIView into UIImage using below code. </p>
  
  <pre><code>+ (UIImage *) imageWithView:(UIView *)view{
       float scale = 1.0f;
      UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, scale);
      [view.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      view.layer.contents = nil;
      return img;
  }
  </code></pre>
  
  <p>There are two problem with this code.</p>
  
  <p><strong>1. When I run this code in background thread(!mainThread)</strong></p>
  
  <p>I faced memory leak problem when renderInContext is called in background thread.</p>
  
  <p><strong>2. When I run this code on Main thread</strong></p>
  
  <p>There is no memory leak but on iPad 3 I am facing some performance issue (my UI hangs when this method is called) while creating image from UIView. As I need to call this function more than 5 times in a seconds so UI hangs gives very bad user experience.</p>
  
  <p>Please guide me if I am doing some thing wrong here?</p>