What happen when we are writing [Obj autorelease] ?
For example:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];<br>
NSMutableString *str = [[[NSMutableString alloc]initWithString:@""] autorelease];<br>
NSLog(str);<br>
[str appendString:@" I"];<br>
NSLog(str);<br>
[str appendString:@" like"];<br>
NSLog(str);<br>
[str appendString:@" programming"];<br>
NSLog(str);<br>
[pool drain];<br>
NSLog(@"%@",str); //invalid
I am confused because i read that "You can add an object to the current autorelease pool for later release by sending it an autorelease message", so when i write
NSMutableString *str = [[[NSMutableString alloc]initWithString:@"my"] autorelease];
1) After executing above statement, Is str now added to autorelease pool?
2) If str is added to autorelease pool, then if we refer str after that (before releasing/draining pool), like...
[str appendString:@" I"];
NSLog(str);
[str appendString:@" like"];
NSLog(str);
[str appendString:@" programming"];
NSLog(str);
then reference of str will be available from autorelease pool(because str is now added to autorelease pool) or from initial memory location of str....??
Confusing...!! Can any one give me clear idea about this!