如何在附加的C数组中正确释放内存?

时间:2010-03-31 19:12:37

标签: iphone c objective-c cocoa

我只是想弄清楚为什么下面的代码泄漏了内存,我有一种有趣的感觉,我没有正确释放阵列内存。这是一个更广泛的Objective-c应用程序中的C函数,我不是C的原生...我曾尝试在数组上使用free(),但感觉这不是整个故事......

有人可以看一看,看看我在这里缺少什么。谢谢!

CFIndex theNumberOfSettings = 3;
CTParagraphStyleSetting theSettings[3] =
{
    {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment},
    {kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing},
    {kCTParagraphStyleSpecifierHeadIndent, sizeof(headIndent), &headIndent}
};

CTParagraphStyleRef theParagraphRef = CTParagraphStyleCreate(theSettings, theNumberOfSettings);

CFAttributedStringSetAttribute(attrString, CFRangeMake(0, CFAttributedStringGetLength(attrString)-1), kCTParagraphStyleAttributeName, theParagraphRef);

CFRelease(theParagraphRef);
free(theSettings);

1 个答案:

答案 0 :(得分:12)

您没有释放未在堆上分配的内存。