Re: NSUserDefaults objects
Re: NSUserDefaults objects
- Subject: Re: NSUserDefaults objects
- From: Ondra Cada <email@hidden>
- Date: Wed, 22 Mar 2006 21:38:00 +0100
Robert,
On 22.3.2006, at 21:16, Robert Walker wrote:
In this case (as per the memory management documentation) I would
assume that I am receiving an autoreleased object
That is not entirely correct: you should assume the object *might be*
(but needs not to be) autoreleased. It can be shared, cached, whatever.
The memory management rules still, of course, do apply: if you want
to keep it for longer than the scope of the current pool, retain it
(presumably /auto/releasing it later, unless you want to keep it for
ever).
Also note that in some cases it may be more prudent to retain/
autorelease at once, even if the usage does *not* go outside the
current pool scope. That is an ufortunate result of widespread using
plain accessors (instead of much safer autoreleasing ones). For
example, this code
id p=[NSAutoreleasePool new];
id ttl=[somethingTitled title];
[something whatever];
NSLog(@"title %@",title);
[p release];
is potentially unsafe, alas (since nothing prevents the whatever
method to create its own nested pool and inside it send [self
setTitle:], rendering thus your original copy unuseable).
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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