Skip to content

Instantly share code, notes, and snippets.

@armhold
Created March 8, 2013 17:36
Show Gist options
  • Save armhold/5118246 to your computer and use it in GitHub Desktop.
Save armhold/5118246 to your computer and use it in GitHub Desktop.
possible memory leak in Nokogiri 1.5.6
#!/usr/bin/env ruby
require 'nokogiri'
def get_memory_usage
`ps -o rss= -p #{Process.pid}`.to_i
end
HTML_CONTENT = "This is some html<br/>This is some more html<br/>" * 10
def run_nokogiri
doc = Nokogiri::HTML.parse(HTML_CONTENT)
doc.css("br").each { |node| node.replace("\n ")}
doc.text
nil
end
i = 0
loop do
run_nokogiri
i += 1
if i % 1000 == 0
GC.start
puts "iteration #{i}"
puts "current memory: #{get_memory_usage}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment