Iphone 在循环中使用CTFontRef创建NSMutableAttributeString时出现问题

Iphone 在循环中使用CTFontRef创建NSMutableAttributeString时出现问题,iphone,ipad,crash,core-text,Iphone,Ipad,Crash,Core Text,我需要为该字符串中的不同范围创建一个具有不同CTFontRef和CTParagraphStyleRef的NSMutableAttributedString 我尝试通过将以下代码放入循环并根据需要更改范围来创建它 CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL); NSDictionary* normalFontAttribute = [[NSDictiona

我需要为该字符串中的不同范围创建一个具有不同CTFontRef和CTParagraphStyleRef的NSMutableAttributedString

我尝试通过将以下代码放入循环并根据需要更改范围来创建它

CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL);
NSDictionary* normalFontAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)normalFontRef,(NSString*)kCTFontAttributeName, nil];
[attributedString addAttributes:normalFontAttribute range:range];

CFRelease(normalFontRef);
[normalFontAttribute release];
normalFontAttribute = nil;

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
NSDictionary* paragraphAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)paragraphStyle,(NSString*)kCTParagraphStyleAttributeName, nil];
[attributedString addAttributes:paragraphAttribute range:range];

CFRelease(paragraphStyle);
paragraphAttribute release];
paragraphAttribute = nil;
我的问题是:

该应用程序在循环一段时间后在设备中崩溃,没有显示任何细节。 只需关闭应用程序无崩溃报告,控制台中无消息,无gdb断点

更多解释: 我在另一个循环中调用此NSMutableAttributedString创建方法进行其他处理,该循环是崩溃的循环,而不是NSMutableAttributedString创建循环。但是,如果我对调用上述方法进行了评论,并使用create-NSMutableAttributedString,则效果良好,请参见下文

//works fine
attributtedString = [[NSMutableAttributedString alloc] initWithString:stringContent];

//not working 
attributtedString   = [self createattributtedString:stringContent];
//this createattributtedString: method contain the first listed code 

提前感谢,

您可能会有一个无休止的循环

您是否在运行iOS 3.1.xx的设备上运行此功能?此功能仅在3.2及以上版本上可用?@deanWombourne,我在iOS 4.2.2和4.3.1中工作过多少次?可能是内存问题?您不应该返回attributedstring吗?很高兴在这里看到更多代码。@Fossli在createAttributedString函数中,我将属性设置为参数字符串并最终返回。这种内存泄漏仅在设备调试中发现,不会导致崩溃。但它在控制台中显示内存泄漏警告。当字符串内容很大时就会发生这种情况。这可能是他的问题的原因。