OpenGLのアプリでdidReceiveMemoryWarningに応答する方法
-
13-09-2019 - |
質問
私のアプリはメモリを大量に使用しています。通常、それがうまく動作しますが、しばらくして再起動していないロードされたデバイス上で、それは悪名高いメモリ不足エラーで投棄されます。
私はdidReceiveMemoryWarning
と私のキャッシュの一部を解放するために対応したいと思います。
しかし、私は私のアプリは、OpenGL ESのテンプレートのオフに基づいており、ビューコントローラを持っていない問題を抱えています。それはちょうどglViewへの参照を保持しているアプリケーションの委任を持っています。
私が対応できるように、私はトラップdidReceiveMemoryWarning
メッセージをに何ができますか?
解決
これはまたあなたの<のhref = "http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/内で利用可能ですUIApplicationDelegate / applicationDidReceiveMemoryWarning:。」のrel = "noreferrer">アプリケーションデリゲートする
-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
NSLog(@"Received memory warning!");
}
他のヒント
また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;
}
所属していません StackOverflow