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

  • 相关阅读:
    2016北京集训测试赛(十四)Problem A: 股神小L
    2016北京集训测试赛(十三) Problem B: 网络战争
    BZOJ 3473 字符串
    2016北京集训测试赛(十一)Problem C: 树链问题
    微信服务号登陆优化
    重新认识下数组的concat方法
    微信服务号开发碰到的缓存问题!
    关于微信服务号开发的一些总结!
    JQ-weui中的日期选择控件关于时间段的设置!
    用json方法来作深拷贝应该知道的一点东西!
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3449042.html
Copyright © 2011-2022 走看看