Re: retainCount
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