Skip to content

Instantly share code, notes, and snippets.

@queso
Created November 4, 2008 00:30
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 queso/22040 to your computer and use it in GitHub Desktop.
Save queso/22040 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def mem_usage
`ps -o rss= -p #{$$}`.to_i
end
@count = (ARGV[0] || 5).to_i
puts "current process id is #{$$}"
puts "Memory before anything: #{mem_usage}"
@array_a = []
@array_b = []
1000000.times { |n| @array_a << n}
500000.times { |n| @array_b << n}
def a
b
end
def b
c
end
def c
d
end
def d
e
end
def e
@count.times do |n|
puts "Memory before process number #{n}: #{mem_usage}"
@array_a - @array_b
puts "Memory after process number #{n}: #{mem_usage}"
end
end
puts "Memory before process: #{mem_usage}"
a
@array_a = nil
@array_b = nil
GC.start
puts "Memory on complete: #{mem_usage}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment