附加格式的 NSString 泄漏
我的 NSString 上有很多泄漏。我使用appendformat 将字符串附加到它。
这是代码:
NSString *textedetails = [[NSMutableString alloc] init];
if([dico objectForKey:@"alertSerie"] != nil)
{[textedetails appendFormat:@"Numéro de Série: %@ \n",[dico objectForKey:@"alertSerie"]];}
if([dico objectForKey:@"alertDate"] != nil)
{[textedetails appendFormat:@"Date de mise en service: %@ \n",[dico objectForKey:@"alertDate"]];}
if([dico objectForKey:@"alertCli"] != nil)
{[textedetails appendFormat:@"Nom du client associé: %@ \n",[dico objectForKey:@"alertCli"]];}
... //我将文本详细信息放入 UITextField 中并且... [文字详情发布];
该代码在上面代码的第一行和最后一行中给了我泄漏...
泄漏的打印屏幕是 这里!!! 非常感谢您
帮助我!
I have lots of leaks on a NSString. I use appendformat to append strings to it.
Here's the code :
NSString *textedetails = [[NSMutableString alloc] init];
if([dico objectForKey:@"alertSerie"] != nil)
{[textedetails appendFormat:@"Numéro de Série: %@ \n",[dico objectForKey:@"alertSerie"]];}
if([dico objectForKey:@"alertDate"] != nil)
{[textedetails appendFormat:@"Date de mise en service: %@ \n",[dico objectForKey:@"alertDate"]];}
if([dico objectForKey:@"alertCli"] != nil)
{[textedetails appendFormat:@"Nom du client associé: %@ \n",[dico objectForKey:@"alertCli"]];}
...
//I put the textdetails into a UITextField and...
[textedetails release];
That code give me leaks in the first and the last line of the code above...
and the printscreen of the leaks is HERE !!!
Many thanks to help me !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这两个都从未被释放。
试试这个
或这个
both these are never released.
Try this
or this
appendFormat
方法不会直接泄漏。这只是一个后续错误,因为NSMutableString
实例从未被释放。我看到您创建 NSMutableString 实例的两个位置:
这些实例必须在某处发布。
The method
appendFormat
is not directly leaking. It's just a subsequent fault because theNSMutableString
instance is never released.I see two locations where you create a
NSMutableString
instance with:These instance have to be release somewhere.
您可以尝试在使用完变量“textedetails”和“texterecap”后立即释放它。
You can try to release variables "textedetails" and "texterecap" right after you finish it uses.