Do you read the entire file at once? Reading it based on a string, i.e. Using ruby -pe
, ruby -ne
or $stdin.each
should reduce memory usage on garbage collection lines that have been processed.
data = {} $stdin.each do |line|
Save it as script.rb
and move the huge CSV file to this standard input script:
ruby script.rb < data.csv
If you do not like reading from standard input, we will need a small change.
data = {} File.open("data.csv").each do |line|
source share