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. 使用CSS来制作类似「黑幕」的效果

    网上几乎没有看到这类的代码,留个档 .heimu,.heimu a{ background-color: #252525; color:#252525; text-shadow: none; }::s ...

  2. 【简●解】 LG P2730 【魔板 Magic Squares】

    LG P2730 [魔板 Magic Squares] [题目背景] 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 ...

  3. 【贪心】「poj1328」Radar Installation

    建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...

  4. jQuery实现Ajax

    jQuery.ajax([settings]) type:类型,“POST”或“GET”,默认为GET url:发送地址 data:连同请求发送到服务器的数据 dataType:预期服务器返回的数据类 ...

  5. C语言之结构体、联合体

    结构体 1,结构体即为多个基本数据类型组合而成的数据类型.结构体本质上同int等一样同为数据类型,可以定义变量,内部成员不能直接赋值. struct Man { ; ; };  上面是错误的.正确写法 ...

  6. 【php】类型转换

    $a = 9; print_r((array) $a) ; 输出: [0=>9] print_r((array) null); 输出: []

  7. 【STL初步】不定长数组:vector + 集合:set + 映射:map

    一.vector 为了节省空间,有时我们会使用动态数组vector. 定义动态数组 vector<类型名>变量名 vector<int>que //定义que为一个int类型的 ...

  8. numpy模块(对矩阵的处理,ndarray对象)

    6.12自我总结 一.numpy模块 import numpy as np约定俗称要把他变成np 1.模块官方文档地址 https://docs.scipy.org/doc/numpy/referen ...

  9. 我的Python分析成长之路8

    Numpy数值计算基础 Numpy:是Numerical Python的简称,它是目前Python数值计算中最为基础的工具包,Numpy是用于数值科学计算的基础模块,不但能够完成科学计算的任而且能够用 ...

  10. 基于FTP服务器搭建yum源

    本例以CentOS6.8为试验对象,来搭建基于FTP服务器的yum源. 一.配置本地yum源 1.创建挂载目录/yum mkdir /yum 2.挂载镜像 mount -o loop  CentOS- ...