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. vue循环出来列表里面的列表点击click事件只对当前列表有效;

    <div id="app"> <div class=‘b’ v-for='item in items' @click="toggle(item)&quo ...

  2. (30)zabbix Trapper 监控项配置

    概述 zabbix获取数据有超时时间,如果一些数据需要执行比较长的时间才能获取的话,那么zabbix会出现异常,考虑到这种情况,zabbix增加了Trapper功能,客户端自己提交数据给zabbix, ...

  3. OpenGLES2.0着色器语言glsl

    OpenGLES2.0中是强制使用可编程的渲染管线的,使用的是glsl着色器语言,因为着色器语言是使用的GPU,即图形处理单元,而不是CPU,这样可以使CPU从繁重的几何计算和像素的处理中解脱出来了. ...

  4. "javac不是内部或外部命令"的解决办法

    “javac不是内部或外部命令”,而此时的java环境是好用的: 1.先检查 JAVA_HOME  =   C:\Program Files\Java\jdk1.7.0_45 classpath   ...

  5. return_url notify_url

    return_url对返回订单状态进行更新和判断,notify_url为异步调动页面,需要先判断notify_url里是否对订单数据做过处理,避免重复更新数据,然后如果用户付款成功直接关闭页面,会造成 ...

  6. LOGMNR分析redo log和archive log教程

    自Oracle 11g起,无需设置UTL_FILE_DIR就可以使用LOGMNR对本地数据库的日志进行分析,以下是使用LOGMNR的DICT_FROM_ONLINE_CATALOG分析REDO和归档日 ...

  7. Dell Idrac Normal Settings

    racadm安装请查看:http://www.cnblogs.com/zyd112/p/7611022.html racadm语法(远程执行命令):racadm -r <racIpAddr> ...

  8. 【总集】C++ STL类库 vector 使用方法

    介绍: 1.vector 的中文名为向量,可以理解为一个序列容器,里面存放的是相同的数据结构类型,类似于数组但与数组又有微妙的不同. 2.vector 采用的是连续动态的空间来存储数据,它是动态的数组 ...

  9. ffmpeg常见名词解析

    scan_all_pmts, 扫描全部的ts流的"Program Map Table"表.

  10. 北京集训TEST13——PA(Goodness)

    题目: Description 桌面上放有 n 张卡牌.对于每张卡牌,一面是绿色的,另一面是红色的.卡牌的每一面都标有一个整数.对于卡牌a和卡牌b,卡牌a对卡牌b的好感度为卡牌a绿色面的数与卡牌b红色 ...