From: Sebastian Hungerecker Date: 2009-04-30T09:27:27+09:00 Subject: Re: object scope and cleanup ball wrote: > It fails, saying that there are 3 objects (not 2). Presumably because > the previous BinarySearchTree didn't delete the TreeNode. > > Can you explain why? Because the garbace collector doesn't destroy objects as soon as possible. He destroys them when it's convenient or necessary. > And what can I do about it? (including "don't use ObjectSpace that > way") Don't use ObjectSpace that way. An object will be in ObjectSpace longer than it is used (sometimes much longer), so the number of objects of a kind in ObjectSpace means nothing. HTH, Sebastian