Re: What are double asterisks for?
Re: What are double asterisks for?
- Subject: Re: What are double asterisks for?
- From: Mike Ferris <email@hidden>
- Date: Mon, 30 Dec 2002 12:43:11 -0800
Correct. Do not allocate a dictionary to pass in to this method and do
not release the dictionary that is passed back by reference.
-initWithRTFDFileWrapper:(NSFileWrapper *)wrapper
documentAttributes:(NSDictionary **)dict will create the dictionary,
autoreleased, and assign it to *dict if dict != NULL.
If you get an object from some method and that method is not -retain
and does not have "alloc" or "copy" in its name, you should not release
it.
(For the picky, the two exceptions that prove this rule are the
-decodeValueOfObjCType:... and related methods of NSCoder when dealing
with object types, and the fact that top-level objects in a nib file
are retained when the nib is loaded.)
Mike
Begin forwarded message:
From: Andrea Perego <email@hidden>
Date: Mon Dec 30, 2002 2:46:58 AM US/Pacific
To: email@hidden
Subject: Re: What are double asterisks for?
At 1:35 PM -0800 12/29/02, Joseph Jones wrote:
The double asterisks mean a double pointer, or a pointer to a
pointer. This
usually means that the API will create an NSDictionary object for you
and
pass that back in this parameter.
Here is an example of how you should call this API:
NSDictionary *myDict;
NSFileWrapper* fileWrapper = [[NSFileWrapper alloc] init...];
[myObject initWithRTFDFileWrapper:fileWrapper
documentAttributes:&myDict];
...Do something with the document attributes now stored in myDict;
[myDict release];
[fileWrapper release];
I'm dubious about the [myDict release] statement. The comments in the
framework header file (NSAttributedString.h) do not state anything
definite, but I'd guess
that the NSDictionary instance returned by
"-(id)initWithRTFDFileWrapper:(NSFileWrapper *)wrapper
documentAttributes:(NSDictionary **)dict" is an autoreleased one. In
this case, of course, releasing it in your method would cause a crash
later on, when the autorelease pool is deallocated. Please note,
this is just a concern of mine: I had no time/opportunity to test. As
a suggestion, I'd try with [myDict release] first and eliminate it if
it causes trouble.
Happy New year to all!
Andrea Perego
Univ. of Florence - Phys. Dept.
_______________________________________________
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.
_______________________________________________
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.