title: How to avoid memory leak with CTFontCreateWithGraphicsFont?
body: <p>I've reduced a leak issue to this easy to compile code which shows after <code>CTFontCreateWithGraphicsFont</code> use and release <code>ct_font</code>, an extra ref to <code>cg_font</code> will be left. Is this an internal Apple ref count issue or am I missing something around like having to double release <code>cg_font</code> or changing order of the releases? Thanks.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ApplicationServices/ApplicationServices.h&gt;
  
  int main(int argc, char **argv) {
      FILE *f = fopen(&quot;/Library/Fonts/Tahoma.ttf&quot;, &quot;rb&quot;);
      fseek(f, 0, SEEK_END);
      long fsize = ftell(f);
      fseek(f, 0, SEEK_SET);
      
      char* font = (char*)malloc(fsize);
      fread(font, fsize, 1, f);
      fclose(f);
      
      CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, font, fsize, NULL);
      CGFontRef cg_font = CGFontCreateWithDataProvider(provider);
      CTFontRef ct_font = CTFontCreateWithGraphicsFont(cg_font, 36., NULL, NULL);
      CGDataProviderRelease(provider);
  
      //
      
      CFRelease(ct_font);
      CFRelease(cg_font);
      
      printf(&quot;ct_font: %d\ncg_font: %d\n&quot;, (int)CFGetRetainCount(ct_font), (int)CFGetRetainCount(cg_font));
  
      free(font);
      
      return 0;
  }
  </code></pre>
  <p>Result after compile and run:</p>
  <blockquote>
  <p>ct_font: -1</p>
  <p>cg_font: 1</p>
  </blockquote>