> Beacuse in this program
>
> <code>
> a = ""
> 10000.times do
>    a = a + "buble"
> end
> </code>
>
> in each cycle ruby creates a new string with length:
> <No. of cycle> * "buble".length + 1 ('\0')
>
> No. of cycle   Heap
> ------------   ----------
> 1)             a = "buble"
> 2)             a = "bublebuble" , a' = "buble"
> 3)             a = "bublebublebuble", a' = "bublebuble", a'' = "buble"
> etc.
>
> so after n-cycles we have
>     S = n * (("buble".length + 1) + (("buble".length * n + 1)) / 2
> in my program:
>     n = 10000
>     "buble".size = 5
>     S = 10000 * (5 + 1 + 50000 + 1)/2 = 5000 * 50007 = 250_035_000 bytes
>
> In your program the strings occupy only
>   1_000_000 * ("blah".length + 1) = 6_000_000 bytes
>

You refer to cycles inside method "leaker". But this method always
creates the same amount of objects so I don't see reason why ruby eats
more and more memory for each "leaker" call.

loop do
  leaker # call leaker, it creates some amount of objects
  # here all objects are possibly to free (there is no reference to them)
  # so when "leaker" is called one more time and it tries to
  # increase heap capacity it should first frees all these objects
end

My point is that this simple program should use constant amount of
_maximum_ (like mine simple program). memory but it doesn't (even if
we call GC manually it frees memory but heap capacity increases so
each time maximum used memory is greater than before).

-- 
Radosw Bu„Šat

http://radarek.jogger.pl - m blog