iOS에서 Memory Warning 테스트

3503 단어 iOS
아이폰 앱으로 테스트didReceiveMemoryWarning할 때의 노트.

Memory Warning 생성


시뮬레이터


iOS Simultor 메뉴에서
Hardware -> Simulate Memory Warning
재현 가능합니다.
단축키는 [command] + [shift] + M입니다.

실기


다음 privete API를 사용할 수 있습니다.
someFile.m
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];

Memory Warning 캡처


각각 Memory Warning입니다.
- AppDelegate
- ViewController
- UIApplicationDidReceiveMemoryWarningNotification
포착할 수 있습니다.
AppDelegate.m
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    NSLog(@"applicationDidReceiveMemoryWarning");
}
ViewController.m
- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"didReceiveMemoryWarning");
}
someFile.m
- (void)someFunction 
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}

- (void) handleMemoryWarning:(NSNotification *)notification
{
    NSLog(@"handleMemoryWarning");
}
이상

좋은 웹페이지 즐겨찾기