Really quick question that is driving me INSANE. I was wondering if someone could tell me why this line is leaking?
NSString *post = [NSString stringWithFormat:@"<someXML><tagWithVar=%@></tagWithVar></someXML>",var];
post = [NSString stringWithFormat:@"xmlValue=%@",(NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)post,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 )];
I am just encoding a string into a URL format. From my understanding, stringWithFormat: should return an autoreleased object. Apparently that is not the case. It works, but leaks. Any ideas??
You are using the method
CFURLCreateStringByAddingPercentEscapes. If a Core Foundation function has “Create” in its name, it means that you own the returned object. In other words, you’ll need to release theCFStringRefreturned byCFURLCreateStringByAddingPercentEscapes.