iOS 화면 마이그레이션 시 메모리 유출을 멈출 수 없으면
                                            
                                                
                                                
                                                
                                                
                                                
                                                 4784 단어  iOS
                    
Instruments를 조사해도 유출은 보이지 않았다.뭐가 문제야?그것은
dispatch_after 순환을 사용하는 애니메이션입니다. 
 dispatch_after,NSRunLoop,NSTimer 등을 사용하여 순환 처리를 수행할 때 owner의 대상으로 석방되더라도 이들 대상이 강력하게 참고되기 때문에 석방되지 않는다.이번에 설치한 물건.
UIImageView의 사용자 정의 클래스에 UIImage가 설치되어 있고 animationImages와 NSTimer를 통해 애니메이션 덤핑 덤핑 행위를 실현했다.참조: iphone fading of images
 
 원시적 실현
이렇게 하면 순환이 계속 순환하고 ower의 대상은 영원히 개방되지 않습니다
NSTimer *timer = [NSTimer timerWithTimeInterval:4.0 
                                              target:self 
                                            selector:@selector(onTimer) 
                                            userInfo:nil 
                                             repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    [timer fire];
대책 후
NSTimer를 property로 사용하면 View가 사라질 때
invalidate 해방이 필요합니다.@interface JSKSwipeViewController ()
@property (nonatomic) NSTimer *timer;
@end
@implementation JSKSwipeViewController
- (void)startAnimation
{
    _timer = [NSTimer timerWithTimeInterval:4.0
                                     target:self
                                   selector:@selector(onTimer)
                                   userInfo:nil
                                    repeats:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    // stop animation and release
    [self.timer invalidate];
    self.timer = nil;
}
Reference
이 문제에 관하여(iOS 화면 마이그레이션 시 메모리 유출을 멈출 수 없으면), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ykawanabe/items/f7745e33ee88e95f8b04텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)