1

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;
Joel
  • 8,502
  • 11
  • 66
  • 115
  • I'm stupid (and new to objective-c). When I wrote the edit about the date property on MyItem, I realized I forgot to release it in MyItems dealloc. Glad it only took me three hours to figure out.. haha – Joel May 01 '11 at 14:42
  • 1
    It will get better. The missing release in dealloc came to my mind within 2 seconds ;-) – Matthias Bauch May 01 '11 at 14:51
  • Rubber-ducking saves the day again! – jscs May 01 '11 at 18:16

0 Answers0