Difference between [[NSMutableDictionary alloc] initWithObjects:...] and [NSMutableDictionary dictionaryWithObjects:...]?
cocoa, iphone, memory-management, objective-c
Solution
`+dictionaryWithObjects:` returns an autoreleased dictionary `-initWithObjects:` you must release yourself
if you want the dictionary to persist as a instance variable, you should create it with an init method or retain an autoreleased version, either way you should be sure to release it in your dealloc method
An excellent resource on this topic is the Memory Management Programming Guide for Cocoa.
Problem
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't working but I just wanted to confirm. In `awakeFromNib`, if I use `[[NSMutableDictionary alloc] initWithObjects:...]` it actually allocates (iPhone) system memory with this `NSMutableDictionary` data, but when I use `[NSMutableDictionary dictionaryWithObjects:...]` it is only available in the stack right? For example, in the future if I try to access `myMutableDict` from a button press via IBAction, the `myMutableDict` object may have been freed, causing my app to crash, even though I have defined it like so in my .h file, and synthesized it: ``` @property (nonatomic, retain) NSMutableDictionary *myMutableDict; ``` For some reason changing to `[[NSMutableDictionary alloc] initWithObjects:...]` fixed this.