From: Florian Gilcher Date: 2009-11-10T11:32:06+09:00 Subject: Re: Good or best way to allocate a large array Hi, You can manually kickstart the GC by using GC.start. http://ruby-doc.org/core/classes/GC.html#M003682 Otherwise, AFAIK, the MRI GCs before breaking certain memory barriers, but don't quote me on that. (I think it does that by counting mallocs and starting the GC once a certain number is hit) This actually explains this behavior: $ time ruby19 -e 'x=1<<63;Array.new(300_000*20) {1<<63}' real 0m4.091s user 0m3.430s sys 0m0.361s $ time ruby19 -e 'GC.disable; x=1<<63;Array.new(300_000*20) {1<<63}' real 0m2.489s user 0m1.845s sys 0m0.565s But be aware though, that this is not caused by the allocation of the array: $ time ruby19 -e 'x=1<<63;Array.new(300_000*20) {x}' real 0m0.846s user 0m0.735s sys 0m0.049s $ time ruby19 -e 'GC.disable; x=1<<63;Array.new(300_000*20) {x}' real 0m0.778s user 0m0.710s sys 0m0.052s So, before (knowingly) breaking those limits, it might be an option to disable the GC. Handle with care, though. Regards, Florian On Nov 9, 2009, at 9:05 PM, Ralph Shnelvar wrote: > Rick, > > Ok ... but the point is that the objects are not gc'd when things go > out of scope but, instead, when Ruby needs memory, right? > > And if you have a huge array with gobs of objects, the gc is gonna > take a while? > > Ralph