Iphone 当uiwebview loadhtmlstring方法的字符串内容很重时,使应用程序崩溃

Iphone 当uiwebview loadhtmlstring方法的字符串内容很重时,使应用程序崩溃,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在做一个显示注释和许多子命令的应用程序。我在htmlstring中维护所有这些信息,并将其提供给UIWebview-(void)loadhtmlstring:(NSString*)str baseUrl:(NSUrl*)url当注释很少时,此功能可以正常工作。如果注释增加,应用程序将崩溃,并显示内存警告 代码如下: NSMutableString *htmlString = [[NSMutableString alloc] ini

我正在做一个显示注释和许多子命令的应用程序。我在htmlstring中维护所有这些信息,并将其提供给UIWebview
-(void)loadhtmlstring:(NSString*)str baseUrl:(NSUrl*)url当注释很少时,此功能可以正常工作。如果注释增加,应用程序将崩溃,并显示内存警告

代码如下:

NSMutableString *htmlString = [[NSMutableString alloc]
                               initWithString:@"<html><body>"];

for(int i=0;i < commentsCount;++i){
    Comment *comment= [self.commetsArray objectatindex:i];
    [htmlString appendFormat:"<h2>%@</h2>",comment.title];
    [htmlString appendFormat:"<h3>%@</h3>",comment.description];
    for (int j=0;j<comment.subCommentCount;++j){
        SubComment *subComment= [comment.subCommetsArray objectatindex:j];
        [htmlString appendFormat:"<h2>%@</h2>",subComment.title];
        [htmlString appendFormat:"<h3>%@</h3>",subComment.description];
    }
}

[htmlString appendString:@"</body></html>"];
[self.commentWebview
 loadHTMLString:htmlString
        baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[htmlString release];
NSMutableString*htmlString=[[NSMutableString alloc]
initWithString:@“];
对于(int i=0;i对于(int j=0;jCommentsCount
从何而来?经过所有循环后,
htmlString
的大小是多少?也许您创建了一个包含100 Mb内容的字符串8)是否有任何理由使用
++i
而不是
i++
?@user971401这是一种风格偏好,实际使用哪一个没有区别(即:它们应该编译成相同的东西)你不能在loadHTMLString:调用并找出一个断点吗?另外,你有一些奇怪的东西(一个objectatindex:方法,而不是objectatindex:我所期望的),所以我想知道你是否在其他地方有泄漏。你有没有使用泄漏工具?