我应该在原始C阵列中释放对象

时间:2012-10-17 03:25:30

标签: ios memory-management

假设你有课程块

Class Block : NSObject

现在,您想要以C风格

创建数组
Block *blocks[5]; // or calling malloc()
Block *aBlock = [[Block alloc] init];
blocks[0] = aBlock; 
// at this point, aBlock will be hand over to array blocks slot.
// not like NSArray, object of 'Block' will not retain by @property(retain)
// or should I call retain before hand over the value into its array and release afterward?
// should I still call below code to release object ?
// [aBlock release];

有人可以向我解释我之后是否还需要释放aBlock对象?

1 个答案:

答案 0 :(得分:2)

否,因为原始数组不会保留每个Block对象。因此,如果您释放它,则在函数退出范围时将清除所有Block个对象