This is my code:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *string = [[NSString alloc] initWithFormat:@"s"];
[string autorelease];
NSLog(@"retainCount of string is %d", [string retainCount]);
[pool release];
NSLog(@"retainCount of string is %d", [string retainCount]);
When I try to understand autorelease and release, I'm confused. if use [string autorelease], after senting a release message to pool, retainCount of string is still 1. But use [string release] to replace the [string autorelease], finally retainCount of string will be 0. What I know about autorelease is "add an object to the current autorelease pool for later release by sending it an autorelease message". Why I sent it an autorelease message and release the pool, I still can access the object.