How many autorelease you can create in your application? Is there any limit?
I searched for an answer in google, but didn't get any useful info.
And
int main(){
NSAutoreleasepool *pool = [NSAutoreleasepool alloc]init];
NSString *str = [NSString alloc]init];
[pool drain];
}
In google, i found this sample in almost all the articles. With the above code, if we do analyze in Xcode it throws memory leak. Instead if we alloc str in this way NSString *str = [NSString alloc]init]autorelease;
then it does not throw any memory leak.
Which way is correct.
Also in the above code, i found that when [pool drain] statement is executed, then the variable str is released. When we write the same code using "@autorelease" keyword instead of NSAutoreleasePool, what happens. I mean there won't be any statement like [pool drain] if we use @autorelease.
I mean in this way
int main(){
@autorelease{
NSString *str = [NSString alloc]init];
}
}
Thanks Jithen