Re: Memory management questions using UUID example
Re: Memory management questions using UUID example
- Subject: Re: Memory management questions using UUID example
- From: j o a r <email@hidden>
- Date: Sun, 19 Jan 2003 18:24:05 +0100
On Sunday, Jan 19, 2003, at 17:57 Europe/Stockholm, Brian Gilman wrote:
Two (perhaps stupid) questions:
Yes, damn you for asking! ;)
1) Why do you need to cast the uuisStr twice in this method??
It could have been written like this:
+ (NSString *) uniqueString
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *uString = (NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return [uString autorelease];
}
2) When you call [(NSString *)uuidStr autorelease]; does this put
allow
the runtime to handle reference counting??
It simply tags the autoreleased object for a delayed release. This
doesn't mean that it will be deallocated later, only that it will be
released some time in the future = the reference count will be
decremented some time in the future (typically after the current event
loop). Remember, since many objects can be retaining, "haning on", to
an object, releasing it doesn't mean it will be deallocated - unless
the reference count would happen to dip down to 0.
I guess the real question is when do I do an [[alloc] init] and
when I
do an [Object* autorelease]??
Well, you alloc when you want to create an object (or some convenience
method does it for you), and you release, or autorelease, when you no
longer want to hang on to an object.
Read the memory management articles (below) on the difference between
release and autorelease, and when to use which one.
It this the same as using dyn_pointers in C++??
Don't know.
And, finally, is there clear, concise documentation on mem management
in Cocoa??
Of course, among many others:
<file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/MemoryMgmt/index.html>
<
http://www.stepwise.com/Articles/Technical/MemoryManagement.html>
<
http://www.stepwise.com/Articles/Technical/HoldMe.html>
...and don't forget the list archives at:
<
http://cocoa.mamasam.com/>
j o a r
_______________________________________________
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.