iOS ARC NSMutableArray我是否需要在为其分配新内存之前先删除AllObjects [英] IOS ARC NSMutableArray do I need to removeAllObjects before alloc new memory for it

查看:157
本文介绍了iOS ARC NSMutableArray我是否需要在为其分配新内存之前先删除AllObjects的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSMutableArray * arrayTest;

-(void) setContent
{
  //must I call [array removeAllObjects]; ? 
  arrayTest = [[NSMutableArray alloc] init]

  [arrayTest addObject:@"str"];
  ...//add many objects
}

我在不同的代码段中调用了此函数.我需要在之前删除arrayTest的AllObjects,然后每次为arrayTest分配内存吗?我使用ARC. 我不希望每次调用此函数时应用程序的内存都会增加.

I call this function at different code snippet. do I need to removeAllObjects of arrayTest before , then alloc memory for arrayTest every time ? I use ARC . I don't want my app memory to increase every time I call this function.

推荐答案

不,您所拥有的很好.您无需在ARC或非ARC下调用removeAllObjects.

No, what you have is fine. You don't need to call removeAllObjects under ARC or non-ARC.

旧数组被释放后,它将负责释放旧数组中的所有对象.

When the old array is deallocated, it will take care of releasing all of the objects in the old array.

这篇关于iOS ARC NSMutableArray我是否需要在为其分配新内存之前先删除AllObjects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆