我在XCode中遇到内存泄漏问题,我尽力清除分析器指出的所有问题,我的项目在ARC管理下,XCode 4.6.3,Parse.framework 1.2.11。
这个问题似乎与使用Parse.com框架相结合(至少方法的名称暗示:PF_SBJsonParser)。我没有单独使用SBJsonParser,我发现使用grep它是我的项目中包含的Parse二进制文件(大约17MB)的一部分。
我在SO上经历了很多主题,SBJsonParser似乎在过去遭遇内存泄漏,ppl建议不要关注库,而是检查如何处理来自库的数据。我试过了,但看不出任何应该导致这种情况的异常。主要问题是我无法查明麻烦的代码行,因为当点击内存泄漏仪器中的行时,我总是将其称为“汇编程序”。
我正在连接内存泄漏仪器的两个打印屏幕,任何正确方向的建议或指示都将不胜感激!
Backtrace泄漏
Leaked Object # Address Size Resp. Library Responsible Frame
__NSCFString 32 < multiple > 1.00 KB Foundation -[NSPlaceholderMutableString initWithCapacity:]
__NSCFString 113 < multiple > 3.44 KB MyLib -[PF_SBJsonParser scanRestOfDictionary:]
__NSCFString 367 < multiple > 11.47 KB Foundation -[NSPlaceholderMutableString initWithCapacity:]
Malloc 176 Bytes 6 < multiple > 1.03 KB MyLib +[PFInternalUtils decodeDictionary:]
__NSCFString 64 < multiple > 2.00 KB Foundation -[NSPlaceholderMutableString initWithCapacity:]
Malloc 32 Bytes 13 < multiple > 416 Bytes MyLib -[PF_SBJsonParser scanRestOfArray:]
Malloc 32 Bytes 359 < multiple > 11.22 KB MyLib -[PF_SBJsonParser scanRestOfString:]
NSMutableArray 21 < multiple > 672 Bytes MyLib -[PF_SBJsonParser scanRestOfArray:]
Malloc 176 Bytes 7 < multiple > 1.20 KB MyLib +[PFInternalUtils decodeDictionary:]
Malloc 64 Bytes 21 < multiple > 1.31 KB MyLib -[PF_SBJsonParser scanRestOfDictionary:]
__NSDictionaryM 7 < multiple > 224 Bytes MyLib +[PFInternalUtils decodeDictionary:]
Malloc 64 Bytes 20 < multiple > 1.25 KB MyLib -[PF_SBJsonParser scanRestOfDictionary:]
__NSDictionaryM 21 < multiple > 672 Bytes MyLib -[PF_SBJsonParser scanRestOfDictionary:]
Malloc <> 32 < multiple > 1.20 KB MyLib -[PF_SBJsonParser scanRestOfString:]
Malloc <> 63 < multiple > 2.53 KB MyLib -[PF_SBJsonParser scanRestOfString:]
__NSCFString 49 < multiple > 784 Bytes MyLib -[PF_SBJsonParser scanRestOfDictionary:]
NSDecimalNumber 29 < multiple > 464 Bytes Foundation -[NSDecimalNumberPlaceholder initWithDecimal:]
Malloc <> 7 < multiple > 1.66 KB MyLib -[PF_SBJsonParser scanRestOfArray:]
呼叫树
Bytes Used # Leaks Symbol Name
29.42 KB 69.2% 917 -[PF_SBJsonParser scanRestOfString:]
29.42 KB 69.2% 917 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfArray:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfDictionary:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfDictionary:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfDictionary:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfArray:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfDictionary:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanRestOfDictionary:]
22.69 KB 53.4% 726 -[PF_SBJsonParser scanValue:]
22.69 KB 53.4% 726 -[PF_SBJsonParser fragmentWithString:]
22.69 KB 53.4% 726 -[PF_SBJsonParser objectWithString:]
22.69 KB 53.4% 726 +[PFInternalUtils parseJSON:]
22.69 KB 53.4% 726 __54+[PFNetworkCommandRunner runCommandAsync:inOperation:]_block_invoke
组件
+0x1eb movl $0, -44(%ebp)
+0x1f2 jmp __54+[PFNetworkCommandRunner runCommandAsync:inOperation:]_block_invoke +0x269
+0x1f4 movl 28(%ebx), %eax
+0x1f7 movl 4290952(%edi), %ecx
+0x1fd movl %ecx, 4(%esp)
+0x201 movl %eax, (%esp)
+0x204 calll DYLD-STUB$$objc_msgSend
+0x209 movl %eax, (%esp)
+0x20c calll DYLD-STUB$$objc_retainAutoreleasedReturnValue
+0x211 movl %eax, -44(%ebp)
+0x214 movl 4300120(%edi), %edx
+0x21a movl 4287040(%edi), %ecx
+0x220 movl %eax, 8(%esp)
+0x224 movl %ecx, 4(%esp)
+0x228 movl %edx, (%esp)
+0x22b calll DYLD-STUB$$objc_msgSend <<< marked as an issue (98.4%)
+0x230 movl %eax, (%esp)
+0x233 calll DYLD-STUB$$objc_retainAutoreleasedReturnValue
+0x238 movl %eax, %ebx
+0x23a movl 4300120(%edi), %eax
+0x240 movl 4288668(%edi), %ecx
+0x246 movl %ebx, 8(%esp)
+0x24a movl %ecx, 4(%esp)
+0x24e movl %eax, (%esp)
+0x251 calll DYLD-STUB$$objc_msgSend <<< marked as issue (1.6%)
+0x256 movl %eax, (%esp)
+0x259 calll DYLD-STUB$$objc_retainAutoreleasedReturnValue
+0x25e movl %eax, -52(%ebp)
+0x261 movl %ebx, (%esp)
+0x264 calll DYLD-STUB$$objc_release
更新
一些背景 - 我有一个DB类User和DB类AdListing,它有一个属性“userId”(指向User的指针)。经过一段时间的挖掘后,我觉得我找到了错误的线路,虽然我不知道如何解决它...看来includeKey会产生很多泄漏 - 如果我注释掉第二行它继续发生没有任何内存泄漏,取消注释会产生上述共享泄漏。
PFQuery *adQuery = [PFQuery queryWithClassName:@"AdListing"];
[adQuery includeKey:@"userId"]; // <== troublemaker
[adQuery whereKey:@"isActivated" equalTo:[NSNumber numberWithBool:YES]];
[adQuery whereKey:@"isRejected" equalTo:[NSNumber numberWithBool:NO]];
[adQuery whereKey:@"userId" notEqualTo:[PFUser currentUser]];
[adQuery setLimit: VERTICAL_SCROLL_STEP];
[adQuery orderByAscending:@"dateAvailableStart"];
[adQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d scores.", objects.count);
}
}];
任何提示或建议都将受到高度赞赏,谢谢!