You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CSV#shift causes unbounded memory growth since v3.3.6 #378
Since csv 3.3.6, reading a file with CSV#shift (and its aliases gets / readline) causes linear unbounded memory growth. It looks like there are unreleased objects that is not garbage collected. Version 3.3.5 is unaffected. CSV#each is not affected.
Steps to reproduce
# repro.rb gem"csv",ENV.fetch("CSV_VERSION")require"csv"require"tmpdir"path=File.join(Dir.tmpdir,"repro.csv")File.write(path,"a,b\n" * 1_000_000)GC.startbefore=GC.stat(:heap_live_slots)csv=CSV.new(File.open(path))nilwhilecsv.getsGC.start(full_mark: true,immediate_sweep: true)puts"csv #{CSV::VERSION}: retained after full GC = #{GC.stat(:heap_live_slots) - before}"
Possible cause: change to CSV#shift in lib/csv.rb:
# 3.3.5 — parse() entered once, paused and resumed via an Enumeratordefshiftparser_enumerator.nextenddefparser_enumerator@parser_enumerator ||= parser.parseend# 3.3.6 — parse() re-entered and abandoned on every calldefshiftparser.parsedo |row|
returnrowendnilend
Activity
Don't leak kept scanner state in loose parser (ruby#379)