From: Ron M Date: 2007-07-22T09:08:25+09:00 Subject: Re: Array flatten memory "leak"? ara.t.howard wrote: > On Jul 19, 2007, at 4:07 PM, Ron M wrote: >> ######################################################################### >> # This unexpectedly grows to 200+MB. > not really? >> ######################################################################### >> 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 But at that point the program is still very small (20MB). But the strange (to me) thing is that is that the next loop - which seems like it shouldn't be allocating more memory since nothing gets saved to variables - where the program quickly grows to over 200MB. >> 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 But this loop increasing memory seemingly without bounds seems somewhat unrelated to the lines above with flatten that only used 20MB, doesn't it?