Hi libxml-ruby folk

I have some long running scripts that parse lots of XML files over a long period of time using XML:Reader and I've been having what appears to be memory leak problems with them. It seems that the read_string method of XML::Reader is the cuplrit. I've narrowed it down to simple test case. Here is the code:

require 'rubygems'
gem 'libxml-ruby', '>= 1.1.2'
require 'xml/libxml'

def parse()
  x = XML::Reader.string("<foo>this is bar</foo>")
  x.next
  x.read_string  # This line causes the leak
  x.close
end

1.upto(2000000) do |i|
  parse
  GC.start if i % 1000 == 0
end

If you comment out the "x.read_string" line everything is fine, it will only use about 20MB of memory, uncomment it however and it will quickly race to 1GB of memory usage. I've tried various ObjectSpace memory inspectors such as Dike but it doesn't show anything that could account for the rapid growth in usage, which makes me think it is a leak in the C extension.

Versions are:

libxml = 2.6.32
libxml-ruby = 1.1.2
Ruby = 1.8.6 p287

I've only tested the above script on OSX but I have experience the leak on various flavours of Linux with Ruby 1.8.5 and 1.8.6.

I'll keep investigating and start looking at the C code of libxml-ruby next, but I thought I'd let someone know about it at this stage.

Thanks

Sean Geoghegan

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to