On Wednesday, 19 February 2003 at 15:02:10 +0900, Matt Armstrong wrote:
> Jim Freeze <jim / freeze.org> writes:
> 
> > I have some code sitting around that used the notation
> > (Yes, it was written long ago before I knew better)
> >
> >   s = ""
> >   s += "whatever"
> >
> > I tried to use it today with 1.8.0, but my program went wild on
> > memory usage.  (Now, remember, this code worked fine under 1.6.7 and
> > possibly 1.7.3.)
> 
> What version do you mean by 1.8.0?  I.e. what is printed with:
> 
>     ruby -e "p RUBY_RELEASE_DATE"
 
 ruby -e "p RUBY_RELEASE_DATE"
 "2003-02-12"

Ok, I have boiled down the code that is causing the problem.
To the best of my recollection, the problem did not occur
on 1.6.7. Here is the code:

#!/usr/bin/env ruby

class App
  def initialize
    @structs = []
    line = "fred "*20
    # Comment out the line below and memory will not blow up.
    100.times { @structs << line.split }
  end#initialize

  def run
    s = ""
    s200 = "a"*200
    9080.times { s += s200 }
    puts s.size  # should be 1816000
  end#run
end#class App

App.new.run


This app grew to 380MB in 1 minute on my computer. A few tweaks
and it can grow to over 1GB or hover around 17MB.

Changing 'line = "fred "*20'  to 'line = "fred "*10' caused
the app to hover around 17MB.
Changing 100.times to 75.times caused the memory to grow much
slower.

I know that += shouldn't be used here, but this smells like
a possible bug since @structs is not related to the loop
in App#run.

-- 
Jim Freeze
----------
"I'd love to go out with you, but I did my own thing and now I've got
to undo it."