2012-03-27 28 views

答えて

4
[[NSNotificationCenter defaultCenter] postNotificationName:      
    @"UIApplicationMemoryWarningNotification" object:[UIApplication sharedApplication]]; 
+0

私のために働かない –

+0

使用UIApplicationDidReceiveMemoryWarningNotification –

7

シミュレータでは、[ハードウェア]に移動し、[メモリの警告をシミュレート]を選択できます。

enter image description here

あなたが本当のiOSデバイス上でこれを実行しようとしている場合、this blog postは、コード内のメモリの警告を送信する方法について説明します。シミュレータで

0

、あなたは、デバイスから1 ...

をシミュレートすることができます、あなたは(例えば、malloc経由)、メモリを大量に割り当てたいことがあります。 手順を実行する必要があります。そうしないと、メモリ警告なしにアプリケーションがクラッシュすることがあります。私のアプリデリゲートで次に

- (void) simulateMemoryWarning:(UITapGestureRecognizer *)gesture { 
[[NSNotificationCenter defaultCenter] postNotificationName:TriggerManualMemoryWarningNotification object:nil]; 

}

:私は、このようなこれをトリガ私のUIの特定の領域にトリプルクリックなど、デバッグモードで私のアプリに隠された何かを置くのが好き

1

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveManualMemoryWarning:) name:TriggerManualMemoryWarningNotification object:nil]; 

- (void) didReceiveManualMemoryWarning:(NSNotification *)notification { 
#ifdef DEBUG 
    SEL memoryWarningSel = @selector(_performMemoryWarning); 
    if ([[UIApplication sharedApplication] respondsToSelector:memoryWarningSel]) { 
     [[UIApplication sharedApplication] performSelector:memoryWarningSel]; 
    }else { 
     NSLog(@"%@",@"Whoops UIApplication no loger responds to -_performMemoryWarning"); 
    } 
    #else 
    NSLog(@"%@",@"Warning: performFakeMemoryWarning called on a non debug build"); 
    #endif 
} 
+0

ありがとう!私は振りジェスチャーの通知を追加し、それは完全に動作します – akaDuality

関連する問題