Bug #5058

Memory leak in Psych.load

Added by nerdd (Rasmus Grouleff) over 9 years ago. Updated over 9 years ago.

Target version:
ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]


I believe there's a memory leak in (({Psych.load})) that affects all long running processes that loads YAML a large number of times.

The expected behaviour is that the memory consumption doesn't grow just because a very simple piece of YAML is loaded and immediately thrown away multiple times.

The easiest way to reproduce it is by executing the following piece of code in irb and look at the memory consumption of the process in a process monitor.

require 'psych'
(1..10000).each {|i| Psych.load "---\nhey\n...\n"}

The two pictures I've attached show what it looks like in my process monitor before and after.

I've run this on Mac OS X 10.6.8.

The compiler is: (({i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)}))

And I've used no ./configure options.


Screen_shot_2011-07-19_at_19.24.05.png (200 KB) Screen_shot_2011-07-19_at_19.24.05.png Before Psych.load nerdd (Rasmus Grouleff), 07/20/2011 03:05 AM
Screen_shot_2011-07-19_at_19.44.38.png (202 KB) Screen_shot_2011-07-19_at_19.44.38.png After 10,000 Psych.load nerdd (Rasmus Grouleff), 07/20/2011 03:05 AM

Updated by tenderlovemaking (Aaron Patterson) over 9 years ago

The leaks are fixed on trunk, but the commits have not been ported back to the 1.9.2 branch:

If you install and use the gem until the backport is applied, that should fix the problem:

gem 'psych', '~> 1.2.0'
require 'psych'

loop do
Psych.load "---\nhey\n...\n"

Updated by tenderlovemaking (Aaron Patterson) over 9 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF