EASY: How does one release memory correctly in the attached C array?
Posted
by Tricky
on Stack Overflow
See other posts from Stack Overflow
or by Tricky
Published on 2010-03-31T19:12:36Z
Indexed on
2010/03/31
19:13 UTC
Read the original article
Hit count: 266
Hi, I'm just trying to work out why the following code is leaking memory and I have a funny feeling that i'm not releasing the array memory correctly. This is a C function in a wider objective-c app and I'm not native to C... i've tried just using free() on the array, but have a feeling this isn't the whole story...
Could someone have a look and see what I'm missing here. Thanks!
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);
© Stack Overflow or respective owner