一个对象的strong 修饰的成员变量,如果要释放, 必须是成员 _ivar = nil;
以下这种方式是可以释放的方式
以下的方式可以释放 person 成员变量
// - 定义 person
@interface ViewController ()
@property (nonatomic, strong) id person;
@property (nonatomic, strong) Person *person1;
@end
// - person 实现
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[StrongReleaseTool releaseInstance:&_person];
[StrongReleaseTool releaseInstance1:&_person1];
NSLog(@"touch end...");
}
@end
//- person 释放
@implementation StrongReleaseTool
+(void)releaseInstance:(id __strong*)person{
*person = nil;
}
+(void)releaseInstance1:(Person * __strong*)person{
*person = nil;
}
@end
// - 打印结果:
2019-08-12 16:46:55.681078+0800 PodLearning[5422:277483] person dealloc....
2019-08-12 16:46:55.681277+0800 PodLearning[5422:277483] person dealloc....
2019-08-12 16:46: