From: Rick DeNatale Date: 2008-01-11T19:33:36+09:00 Subject: Re: why does this code leak? On 1/11/08, Robert Dober wrote: > On Jan 11, 2008 1:19 AM, Rick DeNatale wrote: > > > > > This dynamic instance variable allocation is one of the reasons I now > > prefer Ruby to Smalltalk despite a long relationship with the former. > This is indeed a feature I like a lot, it's supression was however > discussed once, it is still there though. > OTOH who knows maybe Squeak will have it tomorrow, do you think that > would be possible with the actual VM? Well just about anything is possible, as we used to say it's a Simple Matter of Programming. On the other hand, I doubt that it would be practical to do this with Squeak or other ST implementations of which I'm aware. It's pretty fundamental to the design of the VM that instance variables are bound at class definition time to an offset from the beginning of the object. The byte code is optimized for fetching and storing such iv references. When you change a class definition in Smalltalk, say by adding an iv, then the ide recompiles all the methods of the class and any subclasses since this causes ivs to move around in the object instance. Most ST implementations also then mutate any existing instances as well. Dave Ungar, after starting work on Self, used to amuse himself by going to various Smalltalk implementations, adding an instance variable to Object and seeing how long the system lived. I just tried this with Squeak, got a warning that Object can't be changed with the option to proceed anyway, then got a second warning with proceed option, after which it started churning away recompiling all the classes in the image, got through about 30 of the 1500 or so and hung. Ruby is more like self than Smalltalk in this regard. In Ruby IVs are implemented as values in a hash keyed by the iv name. In self, the whole object is basically a collection of named slots, and methods are just executable objects referenced by some of these slots. So in Smalltalk, the class holds both a format descriptor of its instances and a method dictionary used to find instance methods. In Ruby the instance layout is in the object itself and is self described via the hash, while the method dictionary remains in the klass. In self everything is in the 'instance' there are no formal classes but there is a notion of delegation via a special reference slot which is used to find a named slot which is not in the current object. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/