Skip to content

Instantly share code, notes, and snippets.

@flavorjones
Created March 3, 2009 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flavorjones/73503 to your computer and use it in GitHub Desktop.
Save flavorjones/73503 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
#
# memory leak?
#
require 'nokogiri'
1000.times do
doc = Nokogiri::XML("<root><item>1</item></root>")
doc.at('item').remove
putc "."
end
puts
# valgrind output WITHOUT the Node#remove call
==30011==
==30011== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==30011== malloc/free: in use at exit: 937,398 bytes in 15,263 blocks.
==30011== malloc/free: 47,333 allocs, 32,070 frees, 14,197,941 bytes allocated.
==30011== For counts of detected errors, rerun with: -v
==30011== searching for pointers to 15,263 not-freed blocks.
==30011== checked 1,344,580 bytes.
==30011==
==30011== LEAK SUMMARY:
==30011== definitely lost: 0 bytes in 0 blocks.
==30011== possibly lost: 12 bytes in 1 blocks.
==30011== still reachable: 937,386 bytes in 15,262 blocks.
==30011== suppressed: 0 bytes in 0 blocks.
==30011== Rerun with --leak-check=full to see details of leaked memory.
# valgrind output WITH the Node#remove call
==29997==
==29997== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==29997== malloc/free: in use at exit: 1,092,853 bytes in 19,096 blocks.
==29997== malloc/free: 147,428 allocs, 128,332 frees, 29,814,993 bytes allocated.
==29997== For counts of detected errors, rerun with: -v
==29997== searching for pointers to 19,096 not-freed blocks.
==29997== checked 1,432,704 bytes.
==29997==
==29997== LEAK SUMMARY:
==29997== definitely lost: 67,800 bytes in 1,130 blocks.
==29997== possibly lost: 12 bytes in 1 blocks.
==29997== still reachable: 1,025,041 bytes in 17,965 blocks.
==29997== suppressed: 0 bytes in 0 blocks.
==29997== Rerun with --leak-check=full to see details of leaked memory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment