Pop/push, shift/unshift

On 25-Oct-07, at 1:57 PM, Robert D. wrote:

the program was
end

Ruby allocated up to 43M and then decided to release 3M regularly,
seems a very reasonable strategy to me.
I feel that it would be nice to show the exact leaking code so that I
can run it.

You need to be careful what it is you are testing.

Try the tiny variation I’ve supplied below as it is, it’ll execute
relatively benignly. Then comment out the crucial line indicated by
the comment. If you dare. BTW, if you run this make sure you keep on
top of things and kill it before it starts screwing up your machine.
Make sure you don’t have anything important unsaved.

Why don’t we keep all the ‘a’ arrays we generate? Shouldn’t cause a
problem right? If fact if you don’t comment out the crucial line
memory use will grow relatively slowly. If you do comment it out,
then, well, it is your machine.

BTW, the only thing special about nil is that there is only one of
them. You could use a symbol, true/false, a number – just don’t
create a new object.

What happens if you comment out the whole second N.times loop? I get
strangely similar behaviour to just commenting out the crucial line.
Why’s that? Because, in neither case, none of the arrays of Object is
being collected.

If you get the behaviour I’m getting, how do you explain it other
than as a leak?

Innocent bystanders: if you comment out that crucial line before
running the program PAY ATTENTION AND BE READY TO KILL THE PROCESS
BEFORE IT LOCKS UP YOUR MACHINE (very bad on OS X, it is an abrupt
lockup of the system after about 20s on my machine, Ctrl-C won’t
work, get either your activity monitor up and visible or the force
quit dialog).

N = 1000
M = 1000

as = []
loop do
a = []
N.times do
a << Array.new( M ){ Object.new }
end
N.times do
a[0] = nil # <<< the crucial line
a.shift
end

as << a

GC.start
STDERR << ‘.’
end

Cheers,
Bob


what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/


Bob H. – tumblelog at http://
www.recursive.ca/so/
Recursive Design Inc. – weblog at http://www.recursive.ca/
hutch
http://www.recursive.ca/ – works on http://www.raconteur.info/
cms-for-static-content/home/

On 10/25/07, Eric M. [email protected] wrote:

might be unique, not sure. I thought C++ deque does something
Whatever I am not going to try to reproduce an error that might not
even be there.
I have not found any reference to this on Ruby core, could you please
give a pointer to your patch Eric?

Robert

Here it is from over 2 years ago:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/5861
Great thx
message to Bob: no it did not degenerate I only felt that your code
did not at all allow to test this.

But the discussion is all I need to get into this and no more tests are
needed.
Sorry if I was to harsh, somehow I interpreted your posts as cynical,
but that might have been my fault.
But no real problem.

Robert