Skip to content

Commit

Permalink
Add memory leak example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 24, 2020
1 parent 3e38696 commit fd0dbab
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/memory/leak.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env ruby

require 'vips'
require 'objspace'

repeat = 100

def rss
`ps -o rss= -p #{$$}`.chomp.to_i/1024
end

# Doesn't seem to have any affect:
Vips.cache_set_max(0)
Vips.cache_set_max_mem(0)

GC.start
puts "RSS at startup with gems loaded: %d MB" % [rss]

if ARGV.empty?
# A 4MiB JPEG, which decompresses to a 32MiB pixel buffer.
ARGV << "../../spec/vips/thumbnail/IMG_8537.jpg"
end

repeat.times do |i|
ARGV.each do |filename|
img = Vips::Image.new_from_file filename, :access => :sequential
img.write_to_file 'test.jpg', :Q => 50

# Try various permutations of these:
# img.close
# img = nil
# GC.start

print "\rIteration: %-8d RSS: %6d MB File: %-32s".freeze % [i+1, rss, filename]
end
end
puts

GC.start
puts "RSS at exit: %d MB" % [rss]

0 comments on commit fd0dbab

Please sign in to comment.