Setting an object nil versus release+realloc

前端 未结 6 1943
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 01:48

This is not a garbage collected environment

I have a class instance variable which at some point in my runtime, I need to re-initialize with a different data set than it

6条回答
  •  面向向阳花
    2021-02-15 02:13

    If you were on Mac OS, not iPhone OS I would say that it depends on whether the garbage collector is activated or not:

    • with GC: use myArr = nil;
    • without GC: use [myArr release];

    Unfortunately, on iPhone, there is no garbage collection, so if you don't want memory leaks, you have to release your object once you no longer need it.

提交回复
热议问题