Ben Zealley wrote
> [...]
> a, b, c = Array.new(3) { SomeClass.new }
> 
> losing both the .map and the |i|, and that still works (go Ruby! I
> continue to be amazed by how much it can work out...). But all of these
> leave an anonymous array of the variables sitting around, which doesn't
> get GC'd. Can it be done without that, or should I reduce my pedantic
> tendencies slightly and live with it? ;)

The array holds references to the new objects, but the objects don't know
that there is an array:

-------------------------------------------
GC.start
p ObjectSpace.each_object(Array) {}
a, b, c = Array.new(3) { Object.new }
p ObjectSpace.each_object(Array) {}
GC.start
p ObjectSpace.each_object(Array) {}
-------------------------------------------

output:
67
68
67

> Thanks for all the great responses!


btw i like

a, b, c = (1..3).map {Object.new}

or

a, b, c = [42] * 3

but only for immutable types.

:)

cheers

Simon