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;
                    
                }
                
            }
            
        }

  • 相关阅读:
    ORA-28000: the account is locked-的解决办法
    j对ava序列化的学习理解
    Oracle数据库中的时间格式和java中时间格式的转换
    抽象类和接口的区别
    glVertexAttribPointer
    运算符重载
    lua回调时把函数当参数传递时需注意的事项
    visual studio 编译文件生成路径
    UITableView自定义Cell中,纯代码编程动态获取高度
    ASP.NET发送邮件(QQ发送)
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3449042.html
Copyright © 2011-2022 走看看