Ruby's lousy garbage collection

The rumours are true. Screw it they’re not rumours any more. It’s a cold hard fact: Ruby’s garbage collection doesn’t really work all that well.

I am seeing direct evidence about this in my Rails plugin.

It uses a global array that I used to keep rather small (50 elements). I didn’t want to eat memory. Turns out that by keeping arrays small, you’re actually causing memory leaks! How about that!

The reason for this is Ruby’s broken implementation of array.shift and friends. These don’t dereference the old element, which means they stay in memory indefinitely. Bad news. Especially since work on an array means duplicating strings in the first place!

In my development trunk I am now letting the array grow indefinitely. And yes, memory consumption is lower! It’s a strange world out there.

Rumour has it that this will be fixed in new Ruby versions. Not in 1.8.5 though. So I will issue a fix pretty soon.