2009-08-12 2 views
6

내 응용 프로그램은 많은 메모리를 사용합니다. 일반적으로 정상적으로 실행되지만 잠시 후 다시 시작되지 않은로드 된 장치에서는 악명 높은 메모리 부족 오류로 버려집니다.OpenGL 응용 프로그램에서 didReceiveMemoryWarning에 응답하는 방법

나는 didReceiveMemoryWarning에 대응하고 내 캐시의 일부를 확보하고 싶습니다.

하지만 내 애플 리케이션은 OpenGL ES 템플릿을 기반으로하고보기 컨트롤러가 없다는 문제가 있습니다. glView에 대한 참조를 보유하고있는 App Delegate가 있습니다.

응답 할 수 있도록 didReceiveMemoryWarning 메시지를 트랩하려면 어떻게해야합니까?

답변

9

이 내용은 Application Delegate에서도 볼 수 있습니다.

-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application 
{ 
    NSLog(@"Received memory warning!"); 
} 
10

원하는 클래스의 옵저버로 메소드를 UIApplicationDidReceiveMemoryWarningNotification 알림에 추가 할 수도 있습니다. 코드는 다음과 같습니다.

- (void) cleanMemory: (NSNotification*) notification { 
    // Save memory! 
} 

- (id) init { // Or any other function called early on. 
    // other init code 
    [[NSNotificationCenter defaultCenter] 
    addObserver:self selector:@selector(cleanMemory:) 
      name:UIApplicationDidReceiveMemoryWarningNotification 
     object:nil]; 
    return self; 
} 
관련 문제