Hey, I’ve got a quick autorelease question. I understand basically how it works, but I was wondering if the following would create a memory leak.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString* string = [[[NSString alloc] init] autorelease];
[[string retain] autorelease];
[pool drain];
Will the string be sent two release messages?
Think of the your interaction with the retain count of an object purely as a delta.
If you increase it by one, you need to decrease it by one for that object to potentially be released.
So — yes — you increased it by one twice and decreased it by one twice in that code. Two releases on drain will be the result.