Re: Newbie Q - Variables not being retained in class
Re: Newbie Q - Variables not being retained in class
- Subject: Re: Newbie Q - Variables not being retained in class
- From: Charlton Wilbur <email@hidden>
- Date: Fri, 9 Sep 2005 13:52:17 -0400
On Sep 9, 2005, at 11:57 AM, Aaron Wallis wrote:
- ( void ) setupPreferences
{
NSMutableDictionary * defaultPrefs = [NSMutableDictionary
dictionary];
[defaultPrefs setObject:@"%" forKey:@"ExpressionKey"];
[defaultPrefs setObject:@"(" forKey: @"ExpressionIn"];
[defaultPrefs setObject:@")" forKey:@"ExpressionOut"];
myPrefs = [NSUserDefaults standardUserDefaults];
[myPrefs registerDefaults : defaultPrefs];
}
You say [NSMutableDictionary dictionary], which produces an
autoreleased NSMutableDictionary. It is guaranteed to be good for
the context in which it's created, which means your -
setObject:forKey: messages succeed. But at some point when control
is returned to the run loop, the autorelease pool is emptied, which
means that defaultPrefs is finally released and dealloc'd.
If you don't want this to happen, you need to retain it there and
release it at some later point.
Charlton
--
Charlton Wilbur
email@hidden
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden