From: Peter Suk Date: 2005-04-21T07:11:17+09:00 Subject: Re: Question on Singleton Classes (was: Seeing Metaclasses Clearly) On Apr 20, 2005, at 4:57 PM, David A. Black wrote: > Hi -- > > On Thu, 21 Apr 2005, Jim Weirich wrote: > >> A question for those familiar with Ruby internals ... does an object's >> singleton class exist from the moment the object is created, or does >> it >> spring into existence the moment it is needed to hold singleton >> methods? > > I'm pretty sure it springs into existence for the purpose, just to > avoid overpopulating object space with classes. Otherwise there would > be, say, 10000 class objects created for an array of 10000 one-byte > strings, etc. (This is based partly on some familiarity with > internals and also memory of previous discussions with people with > more familiarity with internals.) That would be very hard on GC, since you'd also be creating 10000 new 'roots' to start traversing from. --Peter -- There's neither heaven nor hell, save what we grant ourselves. There's neither fairness nor justice, save what we grant each other.