title: iOS: NSFileHandle vs NSOutputStream for large file download
body: <p>On iOS, our application is downloading a zip file that's approximately 400MB. We're getting intermittent crashing while the file is downloading.</p>
  
  <p>Current I'm using [NSFileHandle writeData:] to write the data as it comes in, and is not being stored in memory. But I'm wondering if the operating system is somehow storing it in memory?</p>
  
  <p>Would NSOutputStream be a better solution to downloading large file? Or possibly standard unix file descriptors?</p>
  
  <p>Our file handle is setup like this:</p>
  
  <pre><code>NSFileManager * fileManager = [NSFileManager defaultManager];
  [fileManager createFileAtPath:tmpFilePath.path contents:nil attributes:nil]; 
  _zipFile = [NSFileHandle fileHandleForWritingAtPath:tmpFilePath.path];
  </code></pre>
  
  <p>Currently my NSURLConnection delegate method looks like this:</p>
  
  <pre><code>- (void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data {
     [_zipFile writeData:data];
  }
  </code></pre>
  
  <p>So the data that comes in from the request is not stored or appended to any other data objects. Shouldn't this just write to disk and not effect memory?</p>
  
  <p>Thanks</p>