Possible Bug in Array Shift

Hi,

I've described a problem with the implementation of Array shift in Ruby 1.8.4 here:

<http://recursive.ca/hutch/index.php?p=361>

I believe that this is the source of the problem Mongrel had experienced with the Mutex and a memory leak.

I've described a possible (single line) solution to this in the article. What I am not completely sure of is what the intended semantics of shift actually is, consequently the suggested fix may be inappropriate. I'll leave that to someone else to decide.

Cheers,
Bob

The following illustrates the problem on OS X (and I believe linux)

accumulator = []
first = true

10.times do |i|
   a = []
   a << "!" * 10000000

   #a[0] = nil

   a.shift

   accumulator << a

   GC.start
   stdout = `ps v -p #{ Process.pid }`
   stdout = stdout.split(%r/\n/)
   printf("\n %s\n", stdout.first) if first
   printf("%6d:: %s\n", i, stdout.last)

   first = false
end

Kirk had mentioned something along these lines but this is the first explanation that also shows where in the C code it's busted.

Ok, but here's the problem, doesn't this also mean that the shifted array continually grows? It seems to me that shift basically makes Array act like an unbounded ring buffer.

Hopefully this gets fixed in ruby very very soon.