B
Blackie
If anyone can explain this I would appreciate it.
I have an IT group knocking Ruby saying that it never releases memory
back to the system (to be available to procs other than Ruby) so
feeling somewhat defensive I went and wrote a dumb script that goes
back and forth between two methods, one cat'ing huge strings and the
other parsing an xml doc with Hpricot.
"task" tops off (in top) around 50M and "other_task" peaks around 150M
(on my machine, CentOS, lastest stable 1.8.6) but when we return to
running "task" for extended periods, memory usage remains at ~150M.
Forgive my ignorance. Can anyone explain this behavior or at least
point me to a place to educate myself?
Many thanks, the script I'm running is below.
--------
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
def other_task
a = []
9999.times do
a << "12345678901234567890123456789012345678901234567890" * 100
end
nil
end
def task
# 500K xml data
data = File.readlines("very_large_output.xml").to_s
temp = Hpricot.XML data
nil
end
puts "In task"
10.times {|i| task; p i}
puts "In other task"
100.times {|i| other_task; p i}
puts "In task (Should memory go down?)"
100.times {|i| task; p i}
I have an IT group knocking Ruby saying that it never releases memory
back to the system (to be available to procs other than Ruby) so
feeling somewhat defensive I went and wrote a dumb script that goes
back and forth between two methods, one cat'ing huge strings and the
other parsing an xml doc with Hpricot.
"task" tops off (in top) around 50M and "other_task" peaks around 150M
(on my machine, CentOS, lastest stable 1.8.6) but when we return to
running "task" for extended periods, memory usage remains at ~150M.
Forgive my ignorance. Can anyone explain this behavior or at least
point me to a place to educate myself?
Many thanks, the script I'm running is below.
--------
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
def other_task
a = []
9999.times do
a << "12345678901234567890123456789012345678901234567890" * 100
end
nil
end
def task
# 500K xml data
data = File.readlines("very_large_output.xml").to_s
temp = Hpricot.XML data
nil
end
puts "In task"
10.times {|i| task; p i}
puts "In other task"
100.times {|i| other_task; p i}
puts "In task (Should memory go down?)"
100.times {|i| task; p i}