From: "ara.t.howard" Date: 2007-07-20T11:45:43+09:00 Subject: Re: Array flatten memory "leak"? On Jul 19, 2007, at 4:07 PM, Ron M wrote: > ###################################################################### > ### > # This unexpectedly grows to 200+MB. not > ###################################################################### > ### > a = (1..200000).map{|x| [x.to_s]};a.length > b = a.flatten.map{|x| x.to_i} ; b.length a #=> big array a.flatten #=> copy of said big array a.flatten #=> copy of flattened array so you take two copies to get one and neglect to call GC.start > puts `grep VmSize /proc/#{$$}/status` ######## under 20 MB > (1..100).each{|x| b.pack("I*").unpack("I*");} > puts `grep VmSize /proc/#{$$}/status` ######## WHOA GREW > TO 1/4 GB. > > > ###################################################################### > ### > # This stays at 20MB > ###################################################################### > ### > a = (1..200000).map{|x| [x.to_s]};a.length > b = a.map{|x| x[0].to_i} ; b.length > puts `grep VmSize /proc/#{$$}/status` ######## under 20 MB > (1..100).each{|x| b.pack("I*").unpack("I*");} > puts `grep VmSize /proc/#{$$}/status` ######## still 20 MB > a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama