I've reduced a leak issue to this easy to compile code which shows after CTFontCreateWithGraphicsFont
use and release ct_font
, an extra ref to cg_font
will be left. Is this an internal Apple ref count issue or am I missing something around like having to double release cg_font
or changing order of the releases? Thanks.
#include <stdio.h>
#include <stdlib.h>
#include <ApplicationServices/ApplicationServices.h>
int main(int argc, char **argv) {
FILE *f = fopen("/Library/Fonts/Tahoma.ttf", "rb");
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("ct_font: %d\ncg_font: %d\n", (int)CFGetRetainCount(ct_font), (int)CFGetRetainCount(cg_font));
free(font);
return 0;
}
Result after compile and run:
ct_font: -1
cg_font: 1