TouchJson内存泄漏?
我正在使用 TouchJson 解析来自 facebooks graph api 的 json 数据。不过,我遇到了一些内存泄漏,我真的不明白为什么......
在我努力寻找泄漏的过程中,我删除了其他所有内容,所以下面的代码是我留下的。泄漏是每个循环一个 NSCFString,我知道它来自对 myItem.date 的赋值,但我不明白为什么?
我正在使用最新版本的 TouchJson
NSError *error;
NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:data error:&error];
NSArray *jsonArray = [jsonDictionary objectForKey:@"data"];
for (NSDictionary *jsonEntry in jsonArray) {
NSDictionary *fromDictionary = [jsonEntry objectForKey:@"from"];
NSString *userId = [fromDictionary objectForKey:@"id"];
// Continue if it is a post from Atlas
if (userId != nil && [userId isEqualToString:@"10465958627"]){
MyItem *myItem = [[MyItem alloc] init];
// This uncommented causes the leak, why?
myItem.date = [jsonEntry objectForKey:@"created_time"];
[myItem release];
}
}
谢谢您的帮助!
编辑:我忘了提及 MyItem 只是一个具有如下属性的对象
@property (nonatomic, copy) NSString *date;
I'm using TouchJson to parse json data from facebooks graph api. I'm getting some memory leaks though, and I don't really understand why...
In my effort to find the leak, I've removed everything else, so the following code is what I'm left with. The leak is one NSCFString for each loop, and I understand that it comes from the assignement to myItem.date, but I don't understand why?
I'm using the latest version of TouchJson
NSError *error;
NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:data error:&error];
NSArray *jsonArray = [jsonDictionary objectForKey:@"data"];
for (NSDictionary *jsonEntry in jsonArray) {
NSDictionary *fromDictionary = [jsonEntry objectForKey:@"from"];
NSString *userId = [fromDictionary objectForKey:@"id"];
// Continue if it is a post from Atlas
if (userId != nil && [userId isEqualToString:@"10465958627"]){
MyItem *myItem = [[MyItem alloc] init];
// This uncommented causes the leak, why?
myItem.date = [jsonEntry objectForKey:@"created_time"];
[myItem release];
}
}
Thank you for your help!
Edit: I forgot to mention that MyItem is just an object with a property like so
@property (nonatomic, copy) NSString *date;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论