1) Disabled ARC.
2) I have the following code:
- (IBAction)btnsecondClicked:(id)sender {
NSString *myname;
myname = retrieveName();
}
NSString * retrieveName()
{
NSString *tmpStr = [[NSString alloc] initWithString "StackOverFlow"];
return tmpStr;
}
I tried with Analyser, and it says
"Object Leaked: allocated object is not referenced later in this execution path and has a retain count of +1"
point at line next to line where retrieName was invoked.
My question:
What is the retain count of the the object ? Should not it be to 2 ?
because:
the first reference count is in
retrieveName()2.the second count is in
btnsecondClicked(), wheremynamevariable holds ?ie:
myname = retrievedName ()-> Does not it increase the reference count ?
In this step, you've created string
NSString *tmpStr = [[NSString alloc] initWithString "StackOverFlow"];. So you've +1 reference count, because alwaysalloc:returns object with +1 count. Then where will you release this? That's why It shows as leak.