title: decoding a HUGE NSString, running out of memory
body: <p>I'm looking for ideas on how to improve a process of decoding a 40+MB NSString with base64 encoding and saving it to a file while being able to fit the process into iPad 1's 256 MB of RAM</p>
  
  <p>I get the NSString from NSXMLParser:</p>
  
  <pre><code>id pointerToString;
  
  - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
  if ([currentElement isEqualToString:@"myElement"]) 
      {
      pointerToString = [string retain];
  }
  }
  </code></pre>
  
  <p>Then I use the pointerToString in a callback:</p>
  
  <pre><code>[handler performSelector: action withObject: pointerToString];
  </code></pre>
  
  <p>In the callback (id value is the pointerToString). I initialize NSData with the pointerToString while decoding it with base64 encoding.</p>
  
  <pre><code>^(id value)
  {
      if ( [[value class] isSubclassOfClass:[NSString class]] ) 
      {
      NSData *data = [NSData dataFromBase64String:value];
      [data writeToFile:file.path atomically:YES];
  }
  }
  </code></pre>
  
  <p>the iPad 1 device runs out of memory and gets killed by the iOS when the memory allocation reaches around 130MB after or during the NSData call. </p>
  
  <p>I have determined that in order to process the 40+MB NSString this way, I'd need about 180+MB of RAM (this is what the maximum memory allocation is on iPad 2 &amp; 3, where the process works because of more RAM)</p>
  
  <p>Any ideas/tips ?</p>
  
  <p>Thank you</p>