• 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: retainCount
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: retainCount


  • Subject: Re: retainCount
  • From: Henri Lamiraux <email@hidden>
  • Date: Fri, 5 Oct 2001 16:01:26 -0700

Yes, it is safe to retain an alloced instance. Retain simply increments
a counter and release decrements it. Autorelease means decrement the
counter later. If you autorelease twice if will be decremented twice
later.

On Friday, October 5, 2001, at 03:21 PM, Rosyna wrote:

NSString* bob=[[NSString alloc] initWithString:@"Bob 0wnz you"];
[[bob retain] release];
[[bob retain] release] doesn't do anything. The refcount at the end is
the same. The string is retained because you created it with an initXXXX
method


NSString* sue=[NSString stringWithString:@"Sue gave Bob a rug-burn."];
[[[[sue retain] autorelease] retain] release];

The string was created autoreleased you retained it once and
autoreleased it. The resulting string is still autoreleased. The extra
retain and release don't do anything.


Henri Lamiraux
Engineering Manager
User Interface Tools Group
Apple


References: 
 >Re: retainCount (From: Rosyna <email@hidden>)

  • Prev by Date: Re: retainCount
  • Next by Date: Re: retainCount
  • Previous by thread: Re: retainCount
  • Next by thread: Re: retainCount
  • Index(es):
    • Date
    • Thread