appendFormat 泄漏
我正在使用仪器来检测一些泄漏,但有些泄漏我无法解决;
NSMutableString *textedetails = [[NSMutableString alloc] init]; ------->2,3%
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"]];} ------->20,9%
NSMutableString *texterecap = [[NSMutableString alloc] init];------->2,3%
if([dico objectForKey:@"alertIndex"] != nil)
{[texterecap appendFormat:@"Index du Compteur: %@ \n",[dico objectForKey:@"alertIndex"]];}
if([dico objectForKey:@"alertE2day"] != nil)
{[texterecap appendFormat:@"Energie produite aujourd'hui: %@ \n",[dico objectForKey:@"alertE2day"]];}
if([dico objectForKey:@"alertEmo"] != nil)
{[texterecap appendFormat:@"Energie produite ce mois-ci: %@ \n",[dico objectForKey:@"alertEmo"]];}
if([dico objectForKey:@"alertEy"] != nil)
{[texterecap appendFormat:@"Energie produite cette année-ci: %@ \n",[dico objectForKey:@"alertEy"]];}
if([dico objectForKey:@"alertCO"] != nil)
{[texterecap appendFormat:@"CO2 économisé cette année: %@ \n",[dico objectForKey:@"alertCO"]];}
if([dico objectForKey:@"alertPerfRel"] != nil)
{[texterecap appendFormat:@"Performance relative: %@ \n",[dico objectForKey:@"alertPerfRel"]];} ------->74,4%
[dico release];
details.numberOfLines=0; // Pour mettre le nombre de lignes possibles à infini.
details.text = [NSString stringWithFormat:@"%@", textedetails ];
recapitulatif.numberOfLines=0;
recapitulatif.text = [NSString stringWithFormat:@"%@", texterecap ];
[textedetails release];
[texterecap release];
...
- (void)dealloc {
[login dealloc];
[motdepasse dealloc];
[responseData dealloc];
[super dealloc];
}
这里:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login et Mot de passe" message:@"Votre login et votre mot de passe sont enregistrés."delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];[alert release]; ------> 100%
我不明白这些泄漏以及如何解决它们!
感谢帮助我:D
编辑:
显然,警报视图的泄漏不是泄漏。
第一次漏水,又漏水了!!!
I'm using instruments to detect some leaks and there's some leaks I can't resolve;
NSMutableString *textedetails = [[NSMutableString alloc] init]; ------->2,3%
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"]];} ------->20,9%
NSMutableString *texterecap = [[NSMutableString alloc] init];------->2,3%
if([dico objectForKey:@"alertIndex"] != nil)
{[texterecap appendFormat:@"Index du Compteur: %@ \n",[dico objectForKey:@"alertIndex"]];}
if([dico objectForKey:@"alertE2day"] != nil)
{[texterecap appendFormat:@"Energie produite aujourd'hui: %@ \n",[dico objectForKey:@"alertE2day"]];}
if([dico objectForKey:@"alertEmo"] != nil)
{[texterecap appendFormat:@"Energie produite ce mois-ci: %@ \n",[dico objectForKey:@"alertEmo"]];}
if([dico objectForKey:@"alertEy"] != nil)
{[texterecap appendFormat:@"Energie produite cette année-ci: %@ \n",[dico objectForKey:@"alertEy"]];}
if([dico objectForKey:@"alertCO"] != nil)
{[texterecap appendFormat:@"CO2 économisé cette année: %@ \n",[dico objectForKey:@"alertCO"]];}
if([dico objectForKey:@"alertPerfRel"] != nil)
{[texterecap appendFormat:@"Performance relative: %@ \n",[dico objectForKey:@"alertPerfRel"]];} ------->74,4%
[dico release];
details.numberOfLines=0; // Pour mettre le nombre de lignes possibles à infini.
details.text = [NSString stringWithFormat:@"%@", textedetails ];
recapitulatif.numberOfLines=0;
recapitulatif.text = [NSString stringWithFormat:@"%@", texterecap ];
[textedetails release];
[texterecap release];
...
- (void)dealloc {
[login dealloc];
[motdepasse dealloc];
[responseData dealloc];
[super dealloc];
}
And here :
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login et Mot de passe" message:@"Votre login et votre mot de passe sont enregistrés."delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];[alert release]; ------> 100%
I don't understand those leaks and howto resolve them!
Thanks to help me :D
EDIT :
Apparently, the leak for the alertview isn't a leak.
For the first leak, there is a leak again !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在第一种情况下,在我看来,您没有释放两个变量:
textedetails
和texterecap
(至少,您没有在所示的代码中执行此操作)。目前尚不清楚您接下来要对这些字符串做什么(分配给属性?),如果您显示更多代码,我可能可以进一步帮助您。你的dealloc方法完全不正确;应该是:
我不知道这是否也可以解决仪器报告的问题,因为在对象上调用dealloc是非常不寻常的(即,我不知道它会产生什么影响) 。
此外,您似乎没有发布
recapitulatif
。我猜,在第二种情况下,警报视图没有被正确关闭。代码正确;我只会尝试实现委托协议来查看
–alertView:willDismissWithButtonIndex:
方法是否实际被调用。In the first case, it seems to me that you are not releasing two variables:
textedetails
andtexterecap
(at least, you are not doing it in the code shown). It is not clear what you are doing next with those strings (assigning to properties?), if you show some more code I might be able to help you further.Your
dealloc
method is quite not right; it should be:I don't know if this could also solve what instruments is reporting, since it is pretty unusual calling
dealloc
on an object (i.e., I don't know what effects it could have).Furthermore, it seems that you are not releasing
recapitulatif
.In the second case, the alert view is not being dismissed correctly, I guess. The code is correct; I would only try and implement the delegate protocol to see if the
– alertView:willDismissWithButtonIndex:
method is actually called.在第一个示例中,您分配/初始化两个 NSMutableString,而不对它们调用释放。 UIAlertView 的用法看起来没问题。
尝试使用 Xcode 中的 Analyze 函数。它将指出发生泄漏的位置并解释原因。
In the first example you are alloc/initing two NSMutableStrings without calling release on them. The UIAlertView usage looks ok.
Try using the Analyze function in Xcode. It will point out where the leaks are occurring and explain why.
为什么你真的想要 NSMutuableString
你可以使用
在你的第二个问题中,如果你将代表作为自己通过,我想就不会泄漏。
(根据您的评论)我认为有些事情是错误的,因为下面的警报视图代码永远不会泄漏。
Why do you really want NSMutuableString
you could have used
and in your second question, if you would have passed the delegate as self, would not be leak i guess.
(according to your comment) i think some thing wrong then, because the below code for alert view will never leak.