Memory management and NSUserDefaults?
Memory management and NSUserDefaults?
- Subject: Memory management and NSUserDefaults?
- From: Mike Nowak <email@hidden>
- Date: Sun, 6 Apr 2003 23:49:16 -0400
I am working my way through the Cocoa Recipes book (thanks Bill!) and I
had a question on managing memory for user defaults (recipe 19). I
noticed that on page 692, in step 6, one of the values from the
defaults database is being retained and I got curious. Lets say I have
a model object with instance variables and a setter for one of those
variables does something like:
[myValue release];
myValue = [newValue copy];
But lets say that when the model was initialized, it got the value from
NSUserDefaults:
myValue = [[NSUserDefaults standardUserDefaults]
objectForKey:@"MyValue"];
Am I supposed to retain this new value? It seems like if my setter gets
used and release this value that I didn't retain, it would cause memory
problems. I'm guessing the rules for defaults are like those of
collections and I shouldn't be releasing values in the defaults.
Should my initialization from the defaults database be more like:
myValue = [[[NSUserDefaults standardUserDefaults]
objectForKey:@"MyValue"] copy];
or
myValue = [[[NSUserDefaults standardUserDefaults]
objectForKey:@"MyValue"] retain];
instead of what I have above?
Thanks in advance for any clarification. Forgive me if this has been
covered before.
--
Mike Nowak
Health Media Research Laboratory, The University of Michigan
http://healthmedia.umich.edu/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.