I'm facing issues with memory leaks in XCode, I tried my best in clearing all issues pointed out by analyzer, my project is under ARC management, XCode 4.6.3, Parse.framework 1.2.11.
The issue seems to be cropping up in combination with using Parse.com framework (at least the name of the method hints that: PF_SBJsonParser). I'm not using SBJsonParser anywhere alone and I found using grep it's part of Parse binary file (approx 17MB) that is included into my project.
I went through lot of topics on SO and SBJsonParser seems to be suffering from memory leaks in past, also ppl suggested not to focus on libraries and rather check how does one handle the data coming from the libraries. I tried that but can't see anything abnormal that should cause that. The main issue is I'm unable to pinpoint the troublesome line of code as I'm always referred to "assembler" when clicking on the row in memory leak instrument.
I'm attaching two print screens from the memory leak instrument, any suggestions or pointers in right direction would be appreciated!
Leaks by 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:]
Call Tree
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
assembly
+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
UPDATE
A bit of background - I have a DB class User and DB class AdListing which has an attribute "userId" (pointer to User). After bit of digging around I think I found the faulty line although I don't know how to fix it... It appear that includeKey generates quite a lot of leaks - if I comment out the second line it goes on without any memory leaks, uncommented generates the above shared leaks.
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);
}
}];
Any hint or suggestion will be highly appreciated, thanks!
To close the topic - rewrote the code to avoid includeKey and the leakage is resolved. it seems Parse SDK is having issues.
Hope it helps people facing the same issue.