I am using ARC and i know the autoreleasepool sends release to all elements inside it. Consider the following example.
-(NSString*)someMethod{
NSString *string1=@"sample text inside string 1"; // string1 add to main autorelease pool
NSString *string2=[[NSString alloc] init]; // string2 retain count is 1
string2=@"sample text inside string 2"; // just assigning
return string1;
}
-(void)viewDidLoad{
NSString *returnedString=[self someMethod];
}
1. so my question is how do i completely release string2 in someMethod?
2. How to completely release string1 from viewDidLoad method completely?
Note: I am using ARC
if i use @autoreleasepool in someMethod then i think it will destroy both string1 and string2. wont it?
And what will be the effect of using @autoreleasepool in someMethod
-(NSString*)someMethod{
@autoreleasepool{
NSString *string1=@"sample text inside string 1"; // string1 add to main autorelease pool
NSString *string2=[[NSString alloc] init]; // string2 retain count is 1
string2=@"sample text inside string 2"; // just assigning
}
return string1;
}