1

我在 XCode 中遇到内存泄漏问题,我尽力清除分析器指出的所有问题,我的项目在 ARC 管理下,XCode 4.6.3,Parse.framework 1.2.11。

这个问题似乎与使用 Parse.com 框架结合起来出现(至少方法的名称暗示:PF_SBJsonParser)。我没有在任何地方单独使用 SBJsonParser,我发现使用 grep 它是包含在我的项目中的 Parse 二进制文件(大约 17MB)的一部分。

我经历了很多关于 SO 和 SBJsonParser 过去似乎遭受内存泄漏的主题,也有人建议不要专注于库,而是检查如何处理来自库的数据。我试过了,但看不到任何导致这种情况的异常。主要问题是我无法确定麻烦的代码行,因为在单击内存泄漏工具中的行时,我总是被称为“汇编程序”。

我附上了内存泄漏仪器的两个打印屏幕,任何正确方向的建议或指针将不胜感激!

回溯泄漏

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”(指向用户的指针)。经过一番挖掘后,我想我找到了有问题的行,尽管我不知道如何修复它......似乎 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);
    }
}];

任何提示或建议将不胜感激,谢谢!

4

1 回答 1

1

关闭主题 - 重写代码以避免 includeKey 并解决泄漏问题。Parse SDK 似乎有问题

希望它可以帮助面临同样问题的人。

于 2013-08-17T18:28:09.193 回答