Created
March 8, 2013 17:36
-
-
Save armhold/5118246 to your computer and use it in GitHub Desktop.
possible memory leak in Nokogiri 1.5.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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