EASY:如何附加Ç阵列中的一个释放内存正确呢? [英] EASY: How does one release memory correctly in the attached C array?
本文介绍了EASY:如何附加Ç阵列中的一个释放内存正确呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是试图找出为什么以下code正在泄漏内存,我有我无法正确释放内存阵列的一个有趣的感觉。这是一个更广泛的Objective-C的应用程序的C函数和我不是本地人到C ......我试着只用free()的阵列上,但有一种感觉,这并不是故事的全部...
有人能看看,看看我在这里失踪。谢谢!
CFIndex theNumberOfSettings = 3;
CTParagraphStyleSetting theSettings [3] =
{
{kCTParagraphStyleSpecifierAlignment,sizeof的(CTTextAlignment),放大器;对齐},
{kCTParagraphStyleSpecifierLineSpacing,sizeof的(lineSpacing),放大器; lineSpacing},
{kCTParagraphStyleSpecifierHeadIndent,sizeof的(headIndent),放大器; headIndent}
};CTParagraphStyleRef theParagraphRef = CTParagraphStyleCreate(theSettings,theNumberOfSettings);CFAttributedStringSetAttribute(attrString,CFRangeMake(0,CFAttributedStringGetLength(attrString)-1),kCTParagraphStyleAttributeName,theParagraphRef);CFRelease(theParagraphRef);
免费(theSettings);
解决方案
您这样做,这不是在堆上分配释放内存。
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);
解决方案
You don't free memory that's not allocated on the heap.
这篇关于EASY:如何附加Ç阵列中的一个释放内存正确呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文