0

NSCellのサブクラスを作成し、必要性を実現するためにsetObjectValue関数をオーバーライドしました。リークの問題があることを除いて、問題はありません。NSCellのsetObjectValue関数は、元のオブジェクトを解放しないようです。

私がクラスに与えるオブジェクトは、NSCopyingプロトコルに準拠し、以下のようにcopyWithZone関数を実装したカスタマイズオブジェクトです。

- (void)setObjectValue:(id < NSCopying >)object {

    // I tried to use [[self objectValue] release]; here but the app crashed 

    [super setObjectValue:object];

    //---- other iniatizlize here ---   
}

- (id)copyWithZone:(NSZone *)zone {
    MapComponent *newCopy = [[MapComponent allocWithZone:zone] initWithType:self.componentType];
    newCopy.myImage = self.myImage;
    return newCopy;
}

私はここで同じ問題を見つけました。答えはありませんが、私の状況をよりよく説明するかもしれません。

4

1 に答える 1

2

これを試して :

- (id)copyWithZone:(NSZone *)zone {
    MapComponent *newCopy = [[[MapComponent allocWithZone:zone] initWithType:self.componentType] autorelease];
    newCopy.myImage = self.myImage;
    return newCopy;
}
于 2010-11-22T08:27:13.730 に答える