Re: Returning structs of NSStrings
Re: Returning structs of NSStrings
- Subject: Re: Returning structs of NSStrings
- From: Alastair Houghton <email@hidden>
- Date: Thu, 25 Mar 2004 10:16:02 +0000
On 25 Mar 2004, at 09:55, Michael Becker wrote:
>
Am 25.03.2004 um 10:22 schrieb Michael Becker:
>
> NSDatat *xmlData = [ network getUserXMLData]:
>
> [ . . . ]
>
> MyUser user;
>
> user.name = [[ xmlContainer descriptionAtIndex:0] autorelease];
>
> user.phone = [[ xmlContainer desciprtionAtIndex:0] autorelease];
>
> user.street = [[ xmlContainer descriptionAtIndex:0] autorelease];
>
>
>
> return user;
>
>
>
>
To my very surprise, this yields the following (for every
>
"autoreleased" NSString):
>
>
*** malloc[2720]: error for object 0x398ed0: Double free
>
>
Removing the autorelease rids me of this error. Am I forgetting that
>
the NSStrings returned by the xmlContainer object are most likely
>
already autoreleased and thus I don't have to care?
That's right. You only need to -release or -autorelease if you -new,
-alloc, -retain, -copy or -mutableCopy an object (or use some other
method with "retain", "copy" or "alloc" in the name).
Whether they're actually autoreleased or not is another question; they
may not be (depending mostly on the preferred style of the person who
wrote the xmlContainer object), in which case they might only have the
same lifetime as the xmlContainer, rather than the lifetime of the
containing autorelease pool. Apple's container objects, for instance,
don't autorelease as they return. Either way, you aren't responsible
for releasing them.
Kind regards,
Alastair.
--
http://www.alastairs-place.net
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.