https://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby
ObjectSpace.trace_object_allocations_start
file = File.open("/some/path/#{Time.now.to_f}-heap.dump", 'w')
ObjectSpace.dump_all(output: file)
file.close
Note that this instrumentation code needs to be in the Ruby process that is gobbling memory. In a multi-threaded environment, like Sidekiq, this code needs to be executed in a worker.
Install Heapy, then:
heapy read some/path/123.456-heap.dump
Note the generation # that seems unusualy high, then:
heapy read 1587078651.3178177-heap.dump GENERATION_NUMBER
Don't forget to check multiple generations. High object counts arent' a bad thing, and it could just be a normal workload before GC kicks in.