Why isn't this code leaking ?
I am new to development and can not figure this out:

 

     for(NSString *collectionName in jsonObjects)
      {
        NSDictionary *collection = [[NSDictionary alloc] init];
        collection = [jsonObjects valueForKey:collectionName];
        NSArray *items = [[NSArray alloc] initWithArray:[collection valueForKey:@"items"]];
        NSNumber *lastAccess = [[NSNumber alloc] init];
        
        lastAccess = [collection valueForKey:@"lastAccess"];
    
        [items release];
      }

I don't understand why it is, that when I DO release either *lastAccess* or *collection*, the program crashes with EXC_BAD_ACCESS error..., but if I DONT release *items* I get a leak. Can anyone please shed light on this. I thought that if you used alloc, then you owned the reference and must therefore release?

Kind regards,

Mark
Why isn't this code leaking ?
===

I am new to development and can not figure this out:

 

     for(NSString *collectionName in jsonObjects)
      {
        NSDictionary *collection = [[NSDictionary alloc] init];
        collection = [jsonObjects valueForKey:collectionName];
        NSArray *items = [[NSArray alloc] initWithArray:[collection valueForKey:@"items"]];
        NSNumber *lastAccess = [[NSNumber alloc] init];
        
        lastAccess = [collection valueForKey:@"lastAccess"];
    
        [items release];
      }

I don't understand why it is, that when I DO release either *lastAccess* or *collection*, the program crashes with EXC_BAD_ACCESS error..., but if I DONT release *items* I get a leak. Can anyone please shed light on this. I thought that if you used alloc, then you owned the reference and must therefore release?

Kind regards,

Mark