【发布时间】:2016-02-20 02:24:14
【问题描述】:
我有主页/视图,我在列表视图中显示所有记录(仅标题和日期)。
当我点击任何记录时,我会在另一个页面中显示记录的完整信息。 每条记录都有一个需要显示的html字符串值。
为了显示 html 内容,我使用 UILabel 控件,它可以正确显示。
但是当导航在 2 个页面/视图之间来回完成时,它会崩溃。 崩溃报告指向与问题相关的内存。
modifiedContent = [modifiedContent stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: '%@'; font-size:%fpx;}</style>",@"Helvetica",17.0f]];
content.attributedText = [[NSAttributedString alloc] initWithData:[modifiedContent dataUsingEncoding:NSUnicodeStringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil
error:nil];
是否需要更改上述代码以处理内存泄漏或是否需要不同的编码类型。
需要从IOS 7支持到IOS Current Version
下面是堆栈跟踪
MyAppName(1098,0x39d7000) malloc: *** mach_vm_map(size=151552) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
MyAppName(1098,0x39d7000) malloc: *** mach_vm_map(size=151552) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2015-11-19 10:18:59.643 MyAppName[1098:436403] -[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x76954080
2015-11-19 10:18:59.646 MyAppName[1098:436403] -[NSCoder(CACoderAdditions) CA_encodeObject:forKey:conditional:]: ignoring exception -[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x76954080
2015-11-19 10:18:59.650 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
2015-11-19 10:18:59.660 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
2015-11-19 10:18:59.662 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
2015-11-19 10:18:59.675 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
2015-11-19 10:18:59.677 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
2015-11-19 10:18:59.785 MyAppName[1098:436403] *** NSKeyedArchiver warning: replacing existing value for key ''; probable duplication of encoding keys in class hierarchy
(lldb)
【问题讨论】:
-
这些“内存相关”问题是什么?崩溃发生在哪里?异常(如果有的话)说明了什么?代码是使用 ARC 编译的吗?如果不是,则存在内存泄漏。
-
我使用的 Xcode 版本是 8.3,iphone 版本是 9.1,因此我无法直接从 xcode 运行代码。该项目不是ARC编译的。我已经编辑了我的问题,其中包含从 Crittercism 生成的堆栈跟踪
标签: html ios objective-c ios7 uilabel