附加格式的 NSString 泄漏

发布于 2024-12-01 05:01:35 字数 856 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡淡離愁欲言轉身 2024-12-08 05:01:35
NSString *textedetails = [[NSMutableString alloc] init];
NSMutableString *texterecap = [[NSMutableString alloc] init];

这两个都从未被释放。

试试这个

NSString *textedetails = [[[NSMutableString alloc] init] autorelease];
NSMutableString *texterecap = [[[NSMutableString alloc] init] autorelease]; 

或这个

NSMutableString *textedetails = [NSMutableString string];
NSMutableString *texterecap = [NSMutableString string];
NSString *textedetails = [[NSMutableString alloc] init];
NSMutableString *texterecap = [[NSMutableString alloc] init];

both these are never released.

Try this

NSString *textedetails = [[[NSMutableString alloc] init] autorelease];
NSMutableString *texterecap = [[[NSMutableString alloc] init] autorelease]; 

or this

NSMutableString *textedetails = [NSMutableString string];
NSMutableString *texterecap = [NSMutableString string];
失去的东西太少 2024-12-08 05:01:35

appendFormat 方法不会直接泄漏。这只是一个后续错误,因为 NSMutableString 实例从未被释放。

我看到您创建 NSMutableString 实例的两个位置:

... = [[NSMutableString alloc] init];

这些实例必须在某处发布。

The method appendFormat is not directly leaking. It's just a subsequent fault because the NSMutableString instance is never released.

I see two locations where you create a NSMutableString instance with:

... = [[NSMutableString alloc] init];

These instance have to be release somewhere.

你不是我要的菜∠ 2024-12-08 05:01:35

您可以尝试在使用完变量“textedetails”和“texterecap”后立即释放它。

You can try to release variables "textedetails" and "texterecap" right after you finish it uses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文