• 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: Some confusion on memory management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some confusion on memory management


  • Subject: Re: Some confusion on memory management
  • From: Jeff Gilbert <email@hidden>
  • Date: Fri, 20 Jan 2006 10:08:21 -0600

Hi Andy,

On Friday, January 20, 2006, at 09:38AM, Andy Armstrong <email@hidden> wrote:

>On 20 Jan 2006, at 15:32, Jeff Gilbert wrote:
>> Instead, you want to make your own private copy of the value of
>> newString so that you can control the lifetime of the string. So,
>> you would do something like this:
>>
>> - (void)setMyString:(NSString *)newString
>> {
>> 	[myString release];  // forget about the old value of myString
>> 	myString = [newString copy];
>> }
>
>Although if you knew the string you were storing was immutable you
>could just retain a reference to it.

That is true.

In the case of NSString, [newString copy] simply does a [newString retain]. It does not make a new copy in memory so the end result is the same. This will also handle the case that you actually do pass an NSMutableString to setMyString:.

Jeff
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Some confusion on memory management
      • From: Andy Armstrong <email@hidden>
References: 
 >Some confusion on memory management (From: Mike Abdullah <email@hidden>)
 >Re: Some confusion on memory management (From: Jeff Gilbert <email@hidden>)
 >Re: Some confusion on memory management (From: Andy Armstrong <email@hidden>)

  • Prev by Date: Weird problem with Core Data
  • Next by Date: Re: Some confusion on memory management
  • Previous by thread: Re: Some confusion on memory management
  • Next by thread: Re: Some confusion on memory management
  • Index(es):
    • Date
    • Thread