6

アプリが大量のメモリを使用しています。通常は正常に動作しますが、しばらく再起動していないロード済みのデバイスでは、悪名高いメモリ不足エラーで破棄されます。

didReceiveMemoryWarning応答してキャッシュの一部を解放したいと考えています。

しかし、私のアプリは OpenGL ES テンプレートに基づいており、ビュー コントローラーがないという問題があります。glViewへの参照を保持するApp Delegateだけがあります。

didReceiveMemoryWarning応答できるようにメッセージをトラップするにはどうすればよいですか?

4

2 に答える 2

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;
}
于 2009-08-12T19:18:23.350 に答える
9

これは、アプリケーションデリゲート内でも利用できます。

-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
  NSLog(@"Received memory warning!");
}
于 2009-08-12T17:59:54.800 に答える