• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Returning structs of NSStrings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning structs of NSStrings


  • Subject: Re: Returning structs of NSStrings
  • From: j o a r <email@hidden>
  • Date: Thu, 25 Mar 2004 11:07:24 +0100

Ask yourself why you autorelease these strings.

Memory management is not magic, it follows simple rules. Read the
documentation, and search the list archives.

You use the same string for all fields in the struct: "[xmlContainer
descriptionAtIndex: 0]". I don't know how the xmlContainer works, but I
would be very surprised if it created new objects for every call to
"descriptionAtIndex:", most likely it always returns the same object.
Also, rule #1 for memory management in ObjC/Cocoa - if you don't
allocate, don't release. Where did you perform an allocation?

j o a r

On 2004-03-25, at 10.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?
> I just don't want to leak memory, and much more important, don't want
> my app to crash with SIGBUS/SIGSERV etc.

[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.


  • Follow-Ups:
    • Re: Returning structs of NSStrings
      • From: Michael Becker <email@hidden>
References: 
 >Returning structs of NSStrings (From: Michael Becker <email@hidden>)
 >Re: Returning structs of NSStrings (From: Michael Becker <email@hidden>)

  • Prev by Date: Re: Returning structs of NSStrings
  • Next by Date: NSValueTransformer used with table colulms
  • Previous by thread: Re: Returning structs of NSStrings
  • Next by thread: Re: Returning structs of NSStrings
  • Index(es):
    • Date
    • Thread