Skip to content

Instantly share code, notes, and snippets.

@somebox
Created October 7, 2010 15:00
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 somebox/615231 to your computer and use it in GitHub Desktop.
Save somebox/615231 to your computer and use it in GitHub Desktop.
track down memory bloat
# Report how much memory is being used right now
# and call it from different places to debug:
def report_memory(note)
memory_usage = `ps -o rss= -p #{$$}`.to_i
mem_mb = sprintf('%.2f MB', memory_usage/1000.0)
puts "mem [#{note}]: #{mem_mb}"
end
# To force ruby to do garbage collection:
GC.start
# remember that garbage cant be collected unless it's been freed.
@that_big_array = nil
that_var = nil
etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment