开发者

iPhone memory leaking?

开发者 https://www.devze.com 2023-01-26 13:44 出处:网络
Really quick question that is driving me INSANE.I was wondering if s开发者_Go百科omeone could tell me why this line is leaking?

Really quick question that is driving me INSANE. I was wondering if s开发者_Go百科omeone 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 the CFStringRef returned by CFURLCreateStringByAddingPercentEscapes.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号