我正在快速使用ARC进行iOS应用开发。偶尔我需要一个普通的旧c-stru的简单的c-array来完成工作。在ARC之前,我只需将free()
添加到我的dealloc
方法中。使用ARC,不再需要dealloc
。是否有一个我可以添加的ARC指令告诉编译器处理释放我的c-array?
Per Tom的回答是dealloc方法
// EIVertex
struct EIVertex {
GLKVector3 p;
GLKVector3 n;
GLKVector3 barycentric;
GLKVector2 st;
};
typedef struct EIVertex EIVertex;
// ivar declaration
EIVertex *_vertices;
// malloc an array of EIVertex
_vertices = (EIVertex *)malloc([_triangles count] * sizeof(EIVertex));
// Note lack of [super dealloc]
- (void)dealloc{
// ARC will not handle mem. management for plain ole c arrays.
free(_vertices);
}
答案 0 :(得分:3)
你仍然可以重载dealloc。唯一的事情就是你不能明确地称之为它。所以像以前一样写dealloc,但不要在其中调用[super dealloc]
。