Troublesome; when is the release of an autoreference object?
NSString *myString= [NSString stringWithFormat: @"%@", stringVariable];
myString is dependent on stringVariable, whenever stringVariable releases myString immediately releases.
NSString *myString= [NSString stringWithString: @"stringVariable"];
In practice, it is observed that myString can be released immediately after the method completes.
Now, if you change your code and use NSAutoReleasePool
- (void)method { NSAutoreleasePool pool = [[NSAutoreleasePool alloc] init]; NSString *string= [NSString string];
Auto-advertising objects issued when the automatic release pool in which they exist or when the object is freed on which they depend.
Now, if you use a method in a stream, you must use the automatic release pool inside it.
- (void)method { NSAutoreleasePool pool = [[NSAutoreleasePool alloc] init];
source share