XCode 4 +仪器 4:误报泄漏?
自从切换到 XCode 4 以来,泄漏工具显示了大量泄漏,全部来自 JSONKit 和 ASIHTTPRequest,运行 2 分钟后,我泄漏了数百个数组/字典/字符串(来自 jk_create_dictionary、jk_parse_array、HTTPMessage::* 等)总计几百KB。大多数堆栈跟踪都不是源自我的任何调用,其余的完全是无辜的。 我非常肯定 XCode 4 之前的情况并非如此。 我不知道罪魁祸首是谁。任何见解都会很可爱。
更新:
JSONKit 泄漏可能是 JSONDecoder 缓存。
例如:
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];
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.
Update:
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑: 在阅读本答案的其余部分之前:
END_OF_EDIT
不是一个答案,更多的是一个补充,并试图了解发生了什么,因为我也看到了仪器的泄漏。
我就是这样使用 JSONKit 的:
@ssteinberg,这是你遇到的那种泄漏吗? :
请注意,我在进行了一些重负载测试后得到了这个,500 个请求和巨大的 JSON 响应,这解释了泄漏是以 MB 为单位(使用最新的 gh 版本)
请注意,我使用仪器相当新,我不知道如何理解这些结果。据 Frames 报道,是的,这看起来像缓存...但我想确定...
所以我打开了一个 GH 上的问题,我希望@johnezang 或任何人能够告诉我们这一点。
如果这只是对 Instruments 的误解,我深表歉意,我更喜欢这样:)
EDIT : Before you read the rest of this answer:
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 :
@ssteinberg, is that the kind of leaks you're having? :
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 :)
根据 Apple 的 WWDC 2010 视频(使用仪器进行高级内存分析),误报泄漏很少见。有时,泄漏工具会漏掉泄漏,但它报告的泄漏是可靠的。我不太擅长静态,但是您是否检查过以确保您没有在未释放解码器的情况下分配解码器?如果它没有发布并且超出范围,那就构成泄漏,对吗?
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?