iPad用の既存のアプリケーションに問題があります。 Sencha Touch for UI(PhoneGapなし)を部分的に使用して、部分的にネイティブ(ダウンロード、ローカルキャッシングなど)で書かれた非常に洗練されたアプリケーションです。
Application runs fine on both iPad 1 and iPad 2 under iOS4. But with public release of iOS 5 aproblem appears for iPad 1 users. Application crashes after several seconds of work. Some guys write that instead of 78 there are only 30 megs of memory available for iPad 1 under iOS 5. And the other blackbox is the UIWebView. Nobody knows its internal limitations.
私はJavaScriptとHTMLの面を最適化する方法をいくつか考えています。たとえば、私は構造を最適化し、できる限りスクリプト内のメモリ割り当てを減らしました。また、IMGタグをDIV +背景画像に置き換えました。しかし、クラッシュは残っている。
以下は、この問題に対する非常識な解決策です。
ソリューション
メモリの警告がありますが、JavaScriptの中に何かネイティブも何もリリースすることはできません。だから私は数メガバイトのダミー配列を割り当ててメモリ警告にリリースするというばかげたことをすることにしました。これはナットですが、それは私のために働く:私は簡単なmalloc()を使って最初に100メガバイトのRAMを割り当てることができました。
// Member variable
void* dummy;
// - (void)init
dummy = malloc(100000000L);
システムが尋ねるとfree()で解放してください。
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if (dummy) {
free(dummy);
dummy = nil;
}
}
今回はアプリが長く働いています。これまでのところ良いこと...次のステップ - 可能な繰り返しメモリを解放する。
// Member variable
NSMutableArray* _memoryWorkaround;
// - (void)init
int chunkCount = 100;
int chunkSize = 1L * 1024L * 1024L;//1 megabyte
_memoryWorkaround = [[NSMutableArray alloc] initWithCapacity:chunkCount];
for (int i = 0; i < chunkCount; i++)
[_memoryWorkaround addObject:[NSValue valueWithPointer:malloc(chunkSize)]];
ここには-100メガバイトのメモリが割り当てられています。このパラメータは改訂の対象となります。
これで、必要に応じてメモリを解放することができます。
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if ([_memoryWorkaround count]) {
NSValue* val = [_memoryWorkaround objectAtIndex:0];
free([val pointerValue]);
[_memoryWorkaround removeObject:val];
}
}
残りの自由に残っている時:
- (void)dealloc {
if ([_memoryWorkaround count]) {
for (NSValue* val in _memoryWorkaround)
free([val pointerValue]);
[_memoryWorkaround removeAllObjects];
}
[_memoryWorkaround release];
[super dealloc];
}
最後に行うことは、NSTimerを使ってバッファをchunkCountに1つずつ戻すことです。
私は知っている狂ったようだ。よりよい解決策が存在するか?