Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rebo

macrumors newbie
Original poster
Mar 5, 2008
20
0
Just confused here is there any reason why


_properties = [NSMutableDictionary dictionaryWithObjects:values forKeys:keys];


Causes a crash, where


_properties = [[NSMutableDictionary alloc] initWithObjects:values forKeys:keys];


works fine in an application with bindings?

Thanks, I'm sure this is a very simple thing i'm missing!
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
The first one is autoreleased, so if you don't retain it after creating it, it'll be invalid sometime after method you created it in goes out of scope (you can't tell exactly when, it's whenever the event loop cycles and the runtime drains the autorelease pool). When bindings tries to use it, crash, because it no longer exists.

The second one has a retain count of one because you used alloc, and will not be automatically released. Hence, no crash. You should be sending this object a release at some point in the future (probably in your dealloc method).

You didn't say if you're using garbage collection memory management or not...
 

rebo

macrumors newbie
Original poster
Mar 5, 2008
20
0
Thank you very much HiRez, that explains it!

No not using Garbage collection memory management right now, still pretty new at cocoa programming!
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I guess I'll be the one to be a stickler and say that this is an Objective-C memory management issue, not really a Cocoa issue. There is a Cocoa convention at work in terms of the naming of methods, but autorelease pool issues, retain/release issues etc. are all Objective-C language features.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.