Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created October 22, 2014 13:17
Show Gist options
  • Save niwatako/a0a53909cdd3012abf08 to your computer and use it in GitHub Desktop.
Save niwatako/a0a53909cdd3012abf08 to your computer and use it in GitHub Desktop.
iOS8の実機で実行すると、NSURLConnectionメモリが逼迫しアプリがクラッシュ
//以下のコードをiOS8の実機で実行すると、メモリが逼迫しアプリがクラッシュします。
//iPad 3rd iOS8.1
for (int i = 0; i<200000; i++) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (i % 100 == 0) NSLog(@"%s:%d:%d",__PRETTY_FUNCTION__,__LINE__,i);
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://127.0.0.1/404.html"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:100000000000]; // ダウンロード元URL
NSURLResponse *resp; // 結果を格納するオブジェクト
NSError *err = nil; // エラーを格納するオブジェクト
// 同期的な呼び出し
NSData *result = [NSURLConnection sendSynchronousRequest:req
returningResponse:&resp
error:&err];
[req release];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
[pool drain];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment