I've a tableviewcontroller which stores dictionary objects in an Array, when a row gets selected I push a new view controller on the navigation stack and I pass a dictionary object from the array in it's initializer, the dictionary object will be retained in a property of the new view controller. When I return back to my tableviewcontroller I release the dictionary object in the dealloc of the view controller. But when I scroll down/back in my tableviewcontroller, the dictionary that was passed to the view controller is deallocated in the tableviewcontroller's Array and the program crashes with the message:
BreakdanceSource[1351:607] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key title.'
When I remove the [dictionary release] from the dealloc function of the view controller, the program works and doesn't crash! It's weird because I thought the array also keeps ownership of it's objects so the dictionary shouldn't have been deallocated.
Why can't I release the dictionary object in my view controller? (I've removed the [dictionary release] now in the dealloc and the program works but won't I have a memory leak? )
I've tried this so far!:
imageshack.us/photo/my-images/813/screenshot20110926at610.png I've used the zombies tool and this is my result! What I don't get is that before the dealloc of my view controller the retain count is 1 which should've been 2. Because the array in the tableviewcontroller should own the dictionary and I've a property in my view controller which is @property (retain) NSDictionary* media. I don't know where my dictionary gets released, because now it only gets released in the view controller's dealloc
I've also tried to change the property @property (retain) to @property NSDictionary* media then I use media = [infoDictionary retain] and it doesn't crash.. did my property (retain) not retain it?