zoukankan      html  css  js  c++  java
  • How to resolve 'Potential Leak' issue

    I am using the 'analyze' tool in xcode to check for potential leakages in my app.

    I am getting the following warning as a result.

    enter image description here

    How do I resolve the potential leak shown above? "self.answerArray" is just an array I declared in my header file

    enter image description here

    解决 :

    You've called mutableCopy on the array (which returns a new array with a retain count of +1 - You own it), and you assign it to a property (which I assume is a strong/retain property) and you're not releasing it. You're leaking the memory.

    You should release tempArray after assigning it to the property - and ensure the property is released in your class' dealloc method.

    这个项目中遇到类似的问题

    if (self.newsList) {
            for (int count = 0; count < [ self.newsList count]; count ++) {
                self.currentRecord = [ self.newsList objectAtIndex:count];
                if ([[[self.currentRecord .personVOList objectForKey:@"pk"] stringValue] isEqualToString:((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidPK]) {
                    NSMutableArray * localArray = [((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidNewsList  mutableCopy];
                    self.currentNewsList = localArray; //或者书写为

                    self.currentNewsList[((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidNewsList  mutableCopy];

                    都会有以上的问题存在
                    break;
                    
                }
                
            }
            
        }
    修改方式:

    if (self.newsList) {
            for (int count = 0; count < [ self.newsList count]; count ++) {
                self.currentRecord = [ self.newsList objectAtIndex:count];
                if ([[[self.currentRecord .personVOList objectForKey:@"pk"] stringValue] isEqualToString:((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidPK]) {
                    NSMutableArray * localArray = [((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidNewsList  mutableCopy];
                    self.currentNewsList = localArray; //或者书写为

                   [localArray release];或者

                    NSMutableArray * localArray = [[((KidsAppDelegate*)[[UIApplication sharedApplication]delegate]).currentKidNewsList  mutableCopy] autorelease];


                    break;
                    
                }
                
            }
            
        }

  • 相关阅读:
    windows 核心编程 第2章 U n i c o d e
    在一个类内不可以定义自身类的对象,为什么定义自身类的静态对象又是正确的
    将JPG图片绘制在对话框背景上:(这段代码绝对可以执行)
    小技巧给CEdit设置字体
    惠普 升级两年保修
    DoModal返回1,对话框不能显示,今天碰到项目在用unicode编码,和多字符编码时候出现的
    MFC 绘图
    CString类所有成员函数详解
    mysql 一些问题
    错误:不能实例化抽象类
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3449042.html
Copyright © 2011-2022 走看看