title: 'Failed to allocate memory' error with large array
body: <p>I am trying to import a large text file (approximately 2 million rows of numbers at 260MB) into an array, make edits to the array, and then write the results to a new text file, by writing:</p>
  
  <pre><code>file_data = File.readlines("massive_file.txt")
  file_data = file_data.map!(&amp;:strip)
  file_data.each do |s|
      s.gsub!(/,.*\z/, "")
  end
  File.open("smaller_file.txt", 'w') do |f|
      f.write(file_data.map(&amp;:strip).uniq.join("\n"))
  end
  </code></pre>
  
  <p>However, I have received the error <code>failed to allocate memory (NoMemoryError)</code>.  How can I allocate more memory to complete the task?  Or, ideally, is there another method I can use where I can avoid having to re-allocate memory?</p>