My process memory usage has been increasing steadily, and some probing
pointed me to REXML. I created a test that consisted of feeding 10 xml
files ranging in size from 15kB to 270kB to REXML::Document.new(). The
files are fed smallest to largest. I would think that memory usage
should return back to ~8 MB since the REXML::Document should go out of
scope, and everything should get garbage-collected.
Is there something wrong with my understanding of Ruby or does REXML
hold onto memory?
===Memory Usage===
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ray 26354 0.0 0.2 20724 7920 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 0.0 0.2 20912 7988 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 18.0 0.3 24000 11044 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 31.0 0.4 27696 14772 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 44.0 0.5 28752 15812 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 62.0 0.5 28916 15944 pts/9 S+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 88.0 0.6 34204 21144 pts/9 R+ 22:46 0:00 ruby
mem_test2.rb
ray 26354 57.5 0.7 37236 24272 pts/9 R+ 22:46 0:01 ruby
mem_test2.rb
ray 26354 73.5 0.8 38816 25920 pts/9 R+ 22:46 0:01 ruby
mem_test2.rb
ray 26354 96.0 0.9 42900 29720 pts/9 R+ 22:46 0:01 ruby
mem_test2.rb
===Test Code===
require 'rexml/document'
def construct(i)
#create the string
f = File.open("/tmp/#{i}.xml", 'r')
str = ''
while line = f.gets
str << line
end
f.close
#construct the xml
xml = REXML::Document.new(str)
xml = nil
return nil
end
puts 'USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
COMMAND'
for j in 1..10
construct(j)
GC.start
puts `ps aux | grep 'ruby mem_test2' | grep -v grep`
end
···
--
Posted via http://www.ruby-forum.com/.