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 RMI 与 .NET Remoting
    实现一个压缩Remoting传输数据的Sink:CompressionSink (转载)
    智能部署与更新
    第二章:.NET Remoting基础知识
    创建以Microsoft .NET Remoting为基础的分布式应用架构
    vs2005如何防止代码被反编译
    使用.NET Remoting开发分布式应用——配置文件篇(转载)
    Remoting概述
    高级 .NET Remoting
    第一章:Remoting技术简介
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3449042.html
Copyright © 2011-2022 走看看