iPhone内存漏水? [英] iPhone memory leaking?

查看:90
本文介绍了iPhone内存漏水?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常快速的问题让我开始了INSANE。我想知道是否有人能告诉我为什么这条线路正在泄漏?

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 )];

我只是将字符串编码为URL格式。根据我的理解,stringWithFormat:应该返回一个自动释放的对象。显然事实并非如此。它有效,但泄漏。任何想法?

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??

推荐答案

您正在使用方法 CFURLCreateStringByAddingPercentEscapes 。如果Core Foundation函数的名称中包含Create,则表示您拥有返回的对象。换句话说,您需要释放 CFURLCreateStringByAddingPercentEscapes 返回的 CFStringRef

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);

这篇关于iPhone内存漏水?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆