Watson1978
6/1/2011 - 2:03 AM

gistfile1.txt

$ ruby19 -v              
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.3]

==== case 1 ====
$ ruby19 test_io_read.rb 
** read
265376 KB
** GC.start
3248 KB


==== case 2 ====
$ ruby19 test_io_read.rb
dummy
** read
265368 KB
** GC.start
265376 KB


==== case 3 ====
$ ruby19 test_io_read.rb
** read
264672 KB
** GC.start
264684 KB


==== case 4 ====
$ ruby19 test_io_read.rb
dummy
** read
264668 KB
** GC.start
264676 KB
def memory
  pid = $$
  str = `ps alx | grep '#{pid}.*ruby'`
  str.split[7]
end

unless File.exists? "/tmp/foo"
  File.open("/tmp/foo", "w") {|f|
    f.write "a" * 1024 * 1024 * 256
  }
  puts "** data created"
  exit
end

File.open("/tmp/foo", "r") {|f|
  # case 1
  f.read

  # case 2
  #puts "dummy"
  #f.read

  # case 3
  #f.gets

  # case 4
  #puts "dummy"
  #f.gets
}

puts "** read"
puts memory + " KB"

GC.start

puts "** GC.start"
puts memory + " KB"