title: Saving and restoring CGContext
body: <p>I'm trying to save and restore a CGContext to avoid doing heavy drawing computations for a second time and I'm getting the error <code>&lt;Error&gt;: CGGStackRestore: gstack underflow</code>. </p>
  
  <p>What am I doing wrong? What is the correct way to do this?</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect {
      CGContextRef context = UIGraphicsGetCurrentContext();
  
      if (initialized) {
          CGContextRestoreGState(context);
          //scale context
          return;
      }
  
      initialized = YES;
  
      //heavy drawing computation and drawing
  
      CGContextSaveGState(context);
  }
  </code></pre>