首页 > 解决方案 > NSConcreteHashTable rehashAround: 崩溃

问题描述

帮助!!!当我创建 NSAttributedString 时,它有时会崩溃。当它崩溃时,内存使用量很大。可能是内存不足导致了这次崩溃?在创建NSAttributedString的时候,由于内存不足,图片已经释放,从而导致crash?

- (NSMutableAttributedString *)generateIconImageModel:(CREnterIcon *)iconModel fontSize:(CGFloat)fontSize {
    if (iconModel.image) {
        NSMutableAttributedString *attriString;
        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
        textAttachment.image = iconModel.image;
        textAttachment.bounds = CGRectMake(0, 0, iconModel.showWidth, iconModel.showHeight);
        attriString = [[NSMutableAttributedString alloc] initWithAttributedString:[NSAttributedString attributedStringWithAttachment:textAttachment]];
        [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:fontSize]} range:NSMakeRange(0, attriString.length)];
        return attriString;
    } else {
        return [NSMutableAttributedString new];
    }
}
crashReason=SIGSEGV

Thread 44 Crashed:
0   libobjc.A.dylib                     AutoreleasePoolPage::autoreleaseFullPage(objc_object*, AutoreleasePoolPage*) (in libobjc.A.dylib) + 128
1   libobjc.A.dylib                     objc_object::rootAutorelease2() (in libobjc.A.dylib) + 108
2   Foundation                          hashProbe (in Foundation) + 356
3   Foundation                          -[NSConcreteHashTable rehashAround:] (in Foundation) + 212
4   Foundation                          hashProbe (in Foundation) + 524
5   Foundation                          -[NSConcreteHashTable addObject:] (in Foundation) + 48
6   UIFoundation                        +[NSAttributeDictionary newWithDictionary:] (in UIFoundation) + 1004
7   Foundation                          -[NSConcreteMutableAttributedString setAttributes:range:] (in Foundation) + 56
8   Foundation                          -[NSMutableAttributedString addAttributes:range:] (in Foundation) + 224
9   MyAPP                               -[MSEnterVM generateIconImageModel:fontSize:] (in Myapp) (MSEnterVM.m:293)
10  MyAPP                               -[MSEnterVM settingEnterType:] (in Myapp) (MSEnterVM.m:0)
11  MyAPP                               -[MSEnterVM handleEnterMessage:] (in Myapp) (MSEnterVM.m:94)
12  MyAPP                               __54-[MSDispatchManager onReceiveMessageType:message:]_block_invoke (in Myapp) (MSDispatchManager.m:84)

标签: iosobjective-ccrashnsattributedstring

解决方案


推荐阅读