iPhone应用内存泄漏问题
我发现以下代码出现泄漏。
cell.lblNoOfReplay.text=[NSString stringWithFormat:@"0 Replies. %@",(NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)[[NSString stringWithFormat:@"Last message on %@",[BabbleVilleAppDelegate dateByAddingHours:Babbleoffset withDate:[[arrayPMMainList objectAtIndex:[indexPath section]] objectForKey:@"datetime"]]] stringByReplacingOccurrencesOfString:@"+" withString:@" "], CFSTR(""), kCFStringEncodingUTF8)];
这里我没有分配任何字符串,但是当我检查内存泄漏时,上面的行中有一些泄漏。 可能是由于 kCFAllocatorDefault 导致的,所以有些人遇到了同样的问题,请帮助我。
问候 姆鲁根
I am getting leaks on the following code.
cell.lblNoOfReplay.text=[NSString stringWithFormat:@"0 Replies. %@",(NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)[[NSString stringWithFormat:@"Last message on %@",[BabbleVilleAppDelegate dateByAddingHours:Babbleoffset withDate:[[arrayPMMainList objectAtIndex:[indexPath section]] objectForKey:@"datetime"]]] stringByReplacingOccurrencesOfString:@"+" withString:@" "], CFSTR(""), kCFStringEncodingUTF8)];
Here i dont havent allocated any string but when i check for memory leaks there are some leaks in the above line .
Probably it may be due to kCFAllocatorDefault ,so of someome has come across the same issues , help me out .
Regards
Mrugen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您已经分配了一个字符串。 Core Foundation 对象遵循创建规则:通过名称包含 Create 或 Copy 的函数获得的任何对象都由调用者拥有,并且必须由调用者在使用完毕后释放。
将代码更改为:
另外,请考虑将该行分成多个部分和中间变量。其他看到该代码的人,包括未来的你,都会感谢你。
Yes, you have allocated a string. Core Foundation objects follow the Create rule: any object obtained via a function whose name contains either Create or Copy is owned by the caller and must be released by the caller when it’s finished using it.
Change your code to:
Also, consider breaking that line into multiple pieces and intermediate variables. Other people that see that code, including your future self, will thank you.