TouchJson内存泄漏?

发布于 2024-11-04 13:13:13 字数 1047 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文