Issue #9541 has been reported by Florian Hanke.

----------------------------------------
Bug #9541: Markedly increased Hash memory usage if Hash is cleared before reinsertion.
https://bugs.ruby-lang.org/issues/9541

* Author: Florian Hanke
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
After a recent upgrade to Ruby 2.1.0 I noticed a significant increase in memory usage when using hashes of any size when clearing the hashes before inserting.

The compared versions are:
ruby 1.9.3dev (2011-09-23 revision 33323) [x86_64-darwin12.2.1]
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]

To test this behaviour I repeatedly (10x) filled in 1 million different string keys, each with a nil value.

Results:
- With Ruby 1.9.3, RSS used stays mostly constant (to 157952 when clearing before inserting).
- With Ruby 2.1.0, RSS used grows far more rapidly when the Hash is cleared before inserting (to 241972, mostly right after refilling for the first time), but also jumps up once when this is not done. 

I've uploaded my measurements and test setup here:
https://gist.github.com/floere/9111529

My assumption is that the GC is not run at appropriate times due to more lax GC settings.

Note: I was not sure whether this is a bug or not. It does lead to a marked increase in memory usage for example on Heroku.



-- 
http://bugs.ruby-lang.org/