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.

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

 

解决 :

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

How to resolve 'Potential Leak' issue的更多相关文章

  1. A memory leak issue with WPF Command Binding

    Background In our application, we have a screen which hosts several tabs. In each tab, it contains a ...

  2. iOS 错误 之 Potential leak of an object stored into 'cs'

    存储到 “cs”的对象存在潜在的泄露

  3. Resolve Missing artifact Issue in maven

    https://jingyan.baidu.com/article/d621e8da0a5b192864913f79.html

  4. RocketMQ 源码学习笔记————Producer 是怎么将消息发送至 Broker 的?

    目录 RocketMQ 源码学习笔记----Producer 是怎么将消息发送至 Broker 的? 前言 项目结构 rocketmq-client 模块 DefaultMQProducerTest ...

  5. RocketMQ 源码学习笔记 Producer 是怎么将消息发送至 Broker 的?

    目录 RocketMQ 源码学习笔记 Producer 是怎么将消息发送至 Broker 的? 前言 项目结构 rocketmq-client 模块 DefaultMQProducerTest Roc ...

  6. RocketMQ(二):producer客户端实践

    MQ解耦了生产者和消费者,前提是有一个稳定强大的消息服务,我们只管与之通信即可. 所以,和MqServer通信是什么样的?难否? 0. 发送端demo /** * This class demonst ...

  7. SilverLight - Memory Leak

    There is a memory leak issue in current silverlight project. It occurs in the search function: the m ...

  8. Use UMDH to identify memory leak problem

    We sometimes got memory leak problem, and we need to find the leaked memory, Here is a usful tool fr ...

  9. Android Lint Checks

    Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...

随机推荐

  1. GIMP工具箱的自定义操作

    首选项 中还包含工具箱的自定义操作:

  2. python-小数据池,再谈编码,is和 == 的区别

    一 . 小数据池 # 小数据池针对的是: int, str, bool 在py文件中几乎所有的字符串都会缓存. # id() 查看变量的内存地址 s = 'attila' print(id(s)) 二 ...

  3. shell-code-3-echo用法&printf用法

    ××××××××××××××××××××××××××××××下面是echo××××××××××××××××××××××××××××××× # read 命令从标准输入(即执行时,键盘的输入)中读取一行 ...

  4. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

  5. Java中IO流讲解(一)

    一.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的类都在IO包中 流按流向分为两种:输入流,输出流 流按操作类型分为两种: 字节流 : 字节流可以操作 ...

  6. HTML、CSS知识点总结_D

    一,html+css基础 1-1 Html和CSS的关系 学习web前端开发基础技术需要掌握:HTML.CSS.JavaScript语言.下面我们就来了解下这三门技术都是用来实现什么的: 1. HTM ...

  7. 【13】javascript跨域通信

    javascript跨域通信 同源:两个文档同源需满足 协议相同 域名相同 端口相同 跨域通信方法: 01,通过设置img,script,link,iframe元素的src,href属性为目标url. ...

  8. BNUOJ 4215 最长公共连续子序列

    最长公共连续子序列 Time Limit: 1000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class ...

  9. [android开发篇][android studio 和elipse都需要的流程 android sdk的安装

    第三步.下载并安装AndroidSDK 前面两步,我们已经配置了JDK变量环境,并安装好了Eclipse,通过这两步之后Java的开发环境就准备好了,如果我们只是开发普通的JAVA应用程序的话,那么到 ...

  10. Axure:从简单搜索到联想搜索的部件制作

    导读:最近一直都在整理原型部件,要说准备的最有感触的,当属搜索框无疑.搜索框的整理,前后加起来共耗时两天多.从最开始的按钮和文本框,到后来的图示,提示和联想查询.耗费了不少的心血,有必要总结一下,留个 ...