0

说你有类 Block

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 对象?

4

1 回答 1

2

不,因为原始数组不会保留每个Block对象。所以如果你释放它,所有Block对象都会在函数退出作用域的那一刻被清理掉

于 2012-10-17T03:31:54.797 回答