@interface someview:UIView{
NSTimer* timer;
}
@end
@implementation someview
-(void)dealloc{
NSLog(@"dealloc someview");
[timer invalidate];
timer = nil;
}
-(void)runTimer{
//
}
-(void)someMethod{
timer = [NSTimer timerWithTimeInterval:2.0f target:self selector:@selector(runTimer) userInfo:nil repeats:YES];
}
@end
일부보기를 해제해도 dealloc은 호출되지 않고 타이머는 계속 실행됩니다.NSTimer는 UIView에서 dealloc을 비활성화합니다.
"timer = [NSTimer schedule ...."부분을 주석 처리하면 dealloc가 호출됩니다. 즉, 내 코드의 다른 모든 부분이 올바르게 작동하고 타이머가 범인이라는 의미입니다. runTimer 메서드는 비어 있습니다. 즉, 저와 함께 장난하는 타이머입니다.
에서 호출 한 경우에만 호출되는 'removeFromSuperview'는 내가 "[someview의 killtimer] 및 [someview 자료는, 타이머가 무효화있어하지만 할당 해제는 여전히 불리는되지 않습니다 넣어 – ssj
다음 다른 뭔가가보기를 유지하고 있습니다. – bbum
내가 구현 한 killtimer 메서드가 처음 시도했을 때 작동하지 않는 이유를 모르겠지만 지금 작동합니다. – ssj