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. Life is short.,You need Python

    真棒Python  https://awesome-python.com/ 精选的Python框架,库,软件和资源的精选列表. 灵感来自awesome-php. 真棒Python 管理员面板 算法和设 ...

  2. 条款38:通过复合塑模has-a或“根据某物实现出”

    NOTE: 1.复合(composition)的意义和public继承完全不同. 2.在应用域(application domain),复合意味 has-a(有一个). 在实现域(implementa ...

  3. InnoDB体系架构总结(二)

    事务 确保事务内的SQL都可以同步执行 要么一起成功 要么一起失败.事务有四个特性原子性 一致性,隔离性,持久性 实现方式 开始事务的时候回家记录记录一个LSN日志序列 当事务执行的时候 会首先在In ...

  4. Python中怎么进行单元测试

    既然是测试,那我们得有被测试的代码,我们先定义一个简单的函数,这个函数的功能就是接收一个姓名,并返回一句问候语句. say_hello_function.py def hello_name(name) ...

  5. JavaScript正则表达式-边界符

    ^:表示字符串开始位置,在多行匹配中表示一行的开始位置. /^\w+/匹配字符串中第一个单词. $:表示字符串结束的位置,在多行匹配中表示一行的结束位置. /\w+$/匹配字符串中最后一个单词. /@ ...

  6. Luogu 3423 [POI 2005]BAN-银行票据 (多重背包单调队列优化 + 方案打印)

    题意: 给出 n 种纸币的面值以及数量,求最少使用多少张纸币能凑成 M 的面额. 细节: 好像是要输出方案,看来很是头疼啊. 分析: 多重背包,裸体??? 咳咳,好吧需要低调,状态就出来了: dp [ ...

  7. 关于logging模块重复问题

    logger对象配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import logging # 获取一个新日志logger = ...

  8. HTML、CSS知识点总结_D

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

  9. 【01】let和const命令

    let和const命令   魔芋总结: 01,let声明变量,只在代码块{}内有效. 02,不存在变量提升,只能先声明,再使用.否则报错. 03,暂时性死区 如果代码块中存在let和const声明的变 ...

  10. zabbix的配置之新版微信报警(二)

    zabbix配置2018版本微信报警 centos6.5中微信报警需要Python2.7版本之上,由于服务器是centos6.5.所以需要升级版本2.6到2.7. 具体升级步骤:Python升级版本2 ...