Add Ruby file that leaks memory and generates three heap dumps

Along with the dumps themselves, in a compressed bzip2 archive, as
compression ratio was 30 to 1.
This commit is contained in:
2018-07-08 04:57:00 +01:00
parent 24928de6c3
commit 20f3c19099
2 changed files with 28 additions and 0 deletions

BIN
test/heap-dumps.tar.bz2 Normal file

Binary file not shown.

28
test/leak.rb Normal file
View File

@@ -0,0 +1,28 @@
require 'objspace'
class Leaky
def self.leak
@leak ||= []
end
def doit
noleak = []
50.times do
self.class.leak << 'leaked memory'
noleak << 'not leaked'
end
end
end
def dump_heap(filename)
GC.start
File.open(filename, 'w') { |file| ObjectSpace.dump_all(output: file) }
end
Leaky.new.doit
dump_heap('heap1.jsonl')
Leaky.new.doit
dump_heap('heap2.jsonl')
Leaky.new.doit
dump_heap('heap3.jsonl')