IPhone memory leak?

A really quick question that forces me to INSANE. I was wondering if anyone can tell me why this line is flowing?

NSString *post = [NSString stringWithFormat:@"<someXML><tagWithVar=%@></tagWithVar></someXML>",var]; post = [NSString stringWithFormat:@"xmlValue=%@",(NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)post, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 )]; 

I just encode the string in URL format. In my opinion, stringWithFormat: should return an object with auto-implementation. This is apparently not the case. It works, but leaks. Any ideas?

+4
source share
1 answer

The method CFURLCreateStringByAddingPercentEscapes . If the Core Foundation function has β€œCreate” in its name, it means that you own the returned object. In other words, you need to free the CFStringRef returned by CFURLCreateStringByAddingPercentEscapes .

 NSString *post = [NSString stringWithFormat:@"...", var]; CFStringRef stringRef = CFURLCreateStringByAddingPercentEscapes(...); post = [NSString stringWithFormat:@"xmlValue=%@",(NSString *)stringRef]; CFRelease(stringRef); 
+15
source

All Articles