ARCでは、保持、解放、自動解放などを心配する必要がなくなります。[super dealloc]
も呼び出すことができません。 -(void) dealloc
メソッドは許可されていますが、呼び出されたかどうかはわかりません。Automatic Reference Counting(ARC)では、free()ステートメントはどこに置くのですか?
これはオブジェクトなどのすべてでどのように優れているのですか。-(id) init
のmalloc()
に一致するfree()
はどこに置かれますか?
例:
@implementation SomeObject
- (id) initWithSize: (Vertex3Di) theSize
{
self = [super init];
if (self)
{
size = theSize;
filled = malloc(size.x * size.y * size.z);
if (filled == nil)
{
//* TODO: handle error
self = nil;
}
}
return self;
}
- (void) dealloc // does this ever get called? If so, at the normal time, like I expect?
{
if (filled)
free(filled); // is this the right way to do this?
// [super dealloc]; // This is certainly not allowed in ARC!
}
'free(0)'はノーオペレーションなので、 '空き(fill)'は 'if(filled)free(filled);'を書くための簡単な方法です。 (私は別のポスターがこれを書いているのを見ましたが、それは受け入れられた答えではありませんので、私はここでもそれを残すと思っていました) – paulmelnikow