On Jun 24, 2010, at 2:40 PM, Jens Alfke wrote:
> On Jun 23, 2010, at 5:11 PM, Patrick William Walker wrote:
>> NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
>>      
>> [prefs setObject: @"120" forKey: @"Length"];
>>      
>> [prefs synchronize];
>> 
>> 
>> When the program is run in the iPhone simulator (v3.2, not using 4.0 yet), 
>> it just dies.  Nothing on the console log so I set a breakpoint and got a 
>> backtrace.  It's pointing to the setObject: method call and it's generating 
>> an access exception.  If I comment out the setObject portion, it runs fine.
> 
> My only guess is that you have some other code elsewhere in the app that’s 
> incorrectly calling -release on the shared NSUserDefaults instance, causing 
> it to be dealloced, so the next access to that object will crash. Take a 
> careful look at the other places in your code that use NSUserDefaults.

The other common NSUserDefaults crash is when you read an object from the prefs 
and then over-release that object. The result is a dangling pointer inside 
NSUserDefaults itself, which can crash later when you try to read or write or 
synchronize. (In your example, synchronize may not need to do anything when you 
don't call -setObject:forKey:, so it doesn't trip over the dangling pointer.)

Either way, you should try NSZombies and Guard Malloc next.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to