title: Unable to release a CGContextRef (context is from a CGLayer)
body: <p>When you create a <strong>CGLayer</strong> like so, and then get the context...it appears to be impossible to <strong>release the CGContextRef</strong>?</p>
  
  <p>Releasing the CGLayerRef itself (apparently) works fine.</p>
  
  <p>You'd think you could release the CGContextRef just before releasing the CGLayer - but no? Nor can you release the CGContextRef just after releasing the CGLayer.</p>
  
  <p>If you release the CGContextRef, the app crashes.</p>
  
  <pre><code>CGLayerRef aether = CGLayerCreateWithContext(
      UIGraphicsGetCurrentContext(), CGSizeMake(1024,768), NULL);
  CGContextRef weird = CGLayerGetContext(aether);
  
  // paths, strokes, filling etc
  // paths, strokes, filling etc
  
  // try releasing weird here
  CGLayerRelease(aether);
  // or, try releasing weird here
  </code></pre>
  
  <p>Does anyone know what is going on here?  (Note further that CGContextRelease is indeed just the same as CFRelease, with some nil checking.)</p>
  
  <p>In fact should you never manually release CGContextRef?  Does anyone know?  Cheers.</p>
  
  <pre><code>CGContextRelease(weird); // impossible, not necessary, doesn't work???
  </code></pre>
  
  <hr>
  
  <p>Regarding Joel's spectacular answer below:</p>
  
  <p>Is releasing the <strong>CGLayerRef</strong> correct and proper? Joel has pointed out:<br>
  <em>"Yes, since the function you're obtaining it from has 'Create' in its signature. See: documentation/CoreFoundation/"</em></p>