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

  • 相关阅读:
    java常用英文解释
    干货——myeclipse快捷键
    上海面试经常遇到的事务安全问题
    2016java技术岗面试题
    Echarts 获取后台数据 使用后台数据展示 柱形图
    JS实现的MAP结构数据
    Spring MVC 返回json数据 报406错误 问题解决方案
    junit 注意事项,切记
    JNDI中 java:comp/env 的理解
    JMS发布/订阅消息传送例子
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3449042.html
Copyright © 2011-2022 走看看