NSString auto-return still causes memory leak

I have a simple function that returns an NSString after decoding it. I use it a lot in my application, and it seems to create a memory leak (according to the "leak" tool) every time I use it. Leaks tell me that the problem is in the line where I highlight the NSString, which I am going to return, even if I auto-advertise it. Here is the function:

-(NSString *) decodeValue
{
 NSString *newString;
 newString = [self stringByReplacingOccurrencesOfString:@"#" withString:@"$"];
 NSData *stateData = [NSData  dataWithBase64EncodedString:newString];
 NSString *convertState = [[[NSString alloc] initWithData:stateData encoding:NSUTF8StringEncoding] autorelease];
 return convertState;
}

My understanding [autorelease] is that it should be used in this way ... where I want to hold the object long enough to return it to my function, and then let the offspring autorealize later. Therefore, I believe that I can use this function with the help of such code without manual release:

NSString *myDecodedString = [myString decodeValue];  

, , , . ?

+3
2

, . , , . - , , , - .

+5

Jexe , Leaks , , , , RunLoop , . , , convertState .

0

Source: https://habr.com/ru/post/1738866/


All Articles