Ruby memory usage grows forever when stream is used

OS: Windows7 32bit main memory: 4 GB ruby ​​-v: ruby ​​1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

# big.mkv file size : 1.45GB

ex1.rb

puts $$

File.open("D:/test/big.mkv", "rb") do |f|
  while buff = f.read(4096)
  end
end

sleep 1000

ex1.rb is fine! memory is about 19,756 KB.

But...

ex2.rb

puts $$

th1 = Thread.new do
  loop do
    sleep 1
  end
end

File.open("D:/test/big.mkv", "rb") do |f|
  while buff = f.read(4096)
  end
end

th1.join

ex2.rb memory usage is constantly increasing ... because 1.937.948 KB

I need to use Thread .. Please help me!

+5
source share
1 answer

Fixed file reading errors in ruby ​​1.9. A script I wrote that a ton of data is read ~ 100 times faster on ruby1.9. Please update if possible, it's worth it.

+1
source

All Articles