iphone - appendFormat 泄漏

标签 iphone ios xcode memory-leaks

我正在使用仪器来检测一些泄漏,但有一些泄漏我无法解决;

        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

编辑:

显然,警报 View 的泄漏不是泄漏。

第一次泄露,又泄露了!!!

最佳答案

在第一种情况下,在我看来,您没有释放两个变量:textedetailstexterecap(至少,您没有在所示的代码中执行此操作) )。目前尚不清楚您接下来要对这些字符串做什么(分配给属性?),如果您显示更多代码,我可能可以进一步帮助您。

你的dealloc方法不太正确;应该是:

- (void)dealloc {
    [login release];
    [motdepasse release];
    [responseData release];
    [super dealloc];
}

我不知道这是否也可以解决仪器报告的问题,因为在对象上调用 dealloc 是非常不寻常的(即,我不知道它会产生什么影响)。

此外,您似乎没有发布recapitulatif

在第二种情况下,我猜警报 View 没有被正确关闭。代码正确;我只会尝试实现委托(delegate)协议(protocol)来查看 –alertView:willDismissWithButtonIndex: 方法是否实际被调用。

关于iphone - appendFormat 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7091884/

相关文章:

iphone - 在提交到应用商店之前,是否可以找到 iOS 应用程序的 itunes 链接?

iOS8 方向 : supportedInterfaceOrientations called but no orientation change

iphone - iOS 开发 - 共享屏幕截图

iphone - NSMutableArray 没有正确添加对象?

iphone - 我的一些 NSString 是字母数字的。如何判断哪些包含数字,哪些不包含数字?

iphone - UIPasteBoard 不粘贴音频文件?

c# - Unity 项目仅适用于 IL2CPP 上的开发构建

ios - 将数据从 ViewController 传递到 Viewcontroller,该 Viewcontroller 现在是 TabBarController 的一部分

ios - swift 改变语言

ios - 为什么未显示 Collection Reusable View?