Memory management 如何释放在目标C中使用类别添加的复制属性?

Memory management 如何释放在目标C中使用类别添加的复制属性?,memory-management,retain,objective-c-category,Memory Management,Retain,Objective C Category,我使用category向UITableViewCell添加了一个copy属性,如下所示 NSString const *key = @"CellSelectedBlockKey"; @interface UITableViewCell (CellSelectionBlock) @property (nonatomic, copy) CellSelectedBlock cellSelectedBlock; @end @implementation UITableViewCell (CellSe

我使用category向UITableViewCell添加了一个copy属性,如下所示

NSString const *key = @"CellSelectedBlockKey";

@interface UITableViewCell (CellSelectionBlock)
@property (nonatomic, copy) CellSelectedBlock cellSelectedBlock;
@end

@implementation UITableViewCell (CellSelectionBlock)

- (void)setCellSelectedBlock:(void(^)(UITableView *table, NSIndexPath *indexpath))cellSelectedBlock
{
    objc_setAssociatedObject(self, &key, cellSelectedBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (CellSelectedBlock)cellSelectedBlock
{
    return objc_getAssociatedObject(self, &key);
}
@end
我将如何清除内存(释放),这个属性,因为我无法为它覆盖dealloc方法


我会感谢你在这方面的帮助。关于向现有类添加属性而不进行子类化的最佳方法的任何建议。

具有强引用关联对象策略的关联对象集(
OBJC\u关联\u保留
OBJC\u关联\u保留
OBJC\u关联\u复制
,或
OBJC\u关联\u复制
)当为同一密钥设置新值(或将
nil
设置为清除)时,或当父对象被解除分配时,自动释放,就像使用
retain
/
copy
属性,或使用ARC中的强引用一样。

具有强引用关联对象策略的关联对象集(
OBJC\u ASSOCIATION\u RETAIN
OBJC\u ASSOCIATION\u RETAIN\u nonomic
OBJC\u ASSOCIATION\u COPY
,或
OBJC\u ASSOCIATION\u COPY\u nonomic
)在设置新值(或
nil
设置为清除)时自动释放)对于同一个键,或者在解除分配父对象时,就像使用
保留
/
复制
属性一样,或者使用ARC中的强引用