开发者

XCode 4 + Instruments 4: False positive leaks?

Ever since switching to XCode 4 the leaks tool shows a LOT of leakage, all from JSONKit and ASIHTTPRequest, after a 2 min run I am leaking hundreds of arrays/dictionaries/strings (from jk_create_dictionary, jk_parse_array, HTTPMessage::*, etc.) totaling a few 100s KB. Most of the stack traces don't originate in any of my calls, and the rest are completely innocent. I am pretty positive it was not the case pre-XCode 4. I don't know who the culprit is. Any insight would be lovely.

U开发者_Go百科pdate:

The JSONKit leaks are probably JSONDecoder caching.

For example:

static JSONDecoder *decoder = nil;
if (!decoder) 
    decoder=[[JSONDecoder alloc] init];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[request setCachePolicy:ASIDoNotWriteToCacheCachePolicy];
[request setCompletionBlock:^{
    NSData *response = [request responseData];
    NSDictionary *json = [decoder objectWithUTF8String:[response bytes] length:[response length]];
    // ...
}];
[request setFailedBlock:^{
    // ...
}];

[request startAsynchronous];


EDIT : Before you read the rest of this answer:

If you see that kind of memory leaks, don't blame Instruments or JSONKit... Both are reliable!

...Blame yourself, 99.9% chances your code is leaking the data you parsed with JSONKit!

END_OF_EDIT


Not an answer, more a complement, and an attempt to understand what's going on since I'm seeing leaks too with instruments.

I'm using JSONKit that way :

NSArray *lines = [dataString componentsSeparatedByString:@"\n"];
for (NSString *line in lines) { // I know, strange format isn't? :)
  NSDictionary *json = [line objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
  // use dictionary data...
}

@ssteinberg, is that the kind of leaks you're having? :

XCode 4 + Instruments 4: False positive leaks?

Note that I had this after some heavy load testing, 500 requests with huge JSON responses, which explains leaks are in MB (using latest gh version)

Please note that I'm quite new using Instruments, and I'm not sure how to understand these results. According to Frames reported, yes that looks like Caching... but I'd like to be sure...

So I opened an Issue on GH, I hope that @johnezang, or anyone, will enlight us about this.

All my apologies if that's just a misunderstanding with Instruments, which I would prefer :)


According to Apple's WWDC 2010 videos (Advanced Memory Analysis with Instruments), false positive leaks are rare. Sometimes the Leaks tool misses leaks, but it's reliable for the ones it reports. I'm not all that great with statics, but have you checked to make sure you're not alloc'ing the decoder without releasing it? If it's not released and falls out of scope, that would constitute a leak, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜