> I have made a few other experiments, including implementing my own
TempFile2
> class. If I use the same strategy as Tempfile and use a SimpleDelegator to
> delegate to an instance of File I get the same memory consumption. I
haven't
> figured out why it is so..

Having just written this, I had to do a SimpleDelegator experiment. Here's
the result.

Size of the ruby interpreter after having created 1000 instances of:

  ADelegatingClass: 315MB

  ANondelegatingClass: 2.6MB

Well?

Cheers,

Thomas




Here's the code:

require 'delegate'

class ADelegatingClass < SimpleDelegator
  def initialize
    super([])
  end
end

class ANondelegatingClass < Array
end

temps = []
1000.times {
  |i|
  t = ADelegatingClass.new
  t.size
  temps << t
}

puts "Done"
gets