如何释放方法中生成的对象?
新建一个打印类 初始化代码如下
@implementation Print
-(id)init{
self = [super init];
if (self) {
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(print) userInfo:nil repeats:YES];
//每隔一秒 打印一次
}
}
-(void)print{
NSLog(@"=========================");
}
@end
@implementation PrintViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self AutoPrint];
}
-(void)AutoPrint{
Print *p = [[Print alloc] init];
//生成P对象
}
-(void)StopPrint{
// 想要在这里释放p对象,从内存里清除,代码应该怎么写?
}
@end