我正在爲使用ARC開發iOS應用程序而加速。偶爾,一個簡單的舊c結構ole c - 陣列是我需要完成的工作。在ARC之前,我只需將free()
添加到我的dealloc
方法中。藉助ARC,不再需要dealloc
。我可以添加一條ARC指令來告訴編譯器處理釋放我的c數組嗎?這裏自動引用計數(ARC)。 ARC可以處理一個簡單的ole c-array嗎?
每湯姆的回答是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);
}
EIVertex是一個Objective-C類嗎?你不應該在Objective-C類中使用'sizeof',因爲類的大小可以在運行時改變。也許你想要一個指針數組。 – newacct
@newacct,EIVertex是一個簡單的ole C結構。我只是更新了代碼片段以使其更清晰。對困惑感到抱歉。 – dugla