• 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: Inconsistent Memory Management Rules
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistent Memory Management Rules


  • Subject: Re: Inconsistent Memory Management Rules
  • From: "John C. Randolph" <email@hidden>
  • Date: Sun, 13 Apr 2003 21:32:18 -0700

On Sunday, April 13, 2003, at 11:54 AM, David Blanton wrote:

I have an example that contradicts the rules I have read for Cocoa memory
management.

One rule as I understand it is "If you -alloc, then you -release (or
-autorelease)"

I have code that crashes when using this rule as follows:

NSString * string = [[NSString alloc]init];
string = [string stringByAppendingString:@"steve jobs"];

'string' is a pointer. In the line of code above, you've discarded its previous value (the address of the object returned by your alloc/init pair), and assigned it the address of an autoreleased string (returned from -stringByAppendingString:)

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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: Inconsistent Memory Management Rules
      • From: Jeffrey J Barbose <email@hidden>
References: 
 >Inconsistent Memory Management Rules (From: David Blanton <email@hidden>)

  • Prev by Date: Re: Inconsistent Memory Management Rules
  • Next by Date: Re: Inconsistent Memory Management Rules
  • Previous by thread: Re: Inconsistent Memory Management Rules
  • Next by thread: Re: Inconsistent Memory Management Rules
  • Index(es):
    • Date
    • Thread