From: Dan Sugalski Date: 2002-07-04T03:50:05+09:00 Subject: Re: Ruby implementation Q's At 3:33 AM +0900 7/4/02, Justin Johnson wrote: > > I've had to deal with this particular problem while designing Parrot. >> The only way to do this is with reference counting, but unfortunately >> reference counting has a number of unfortunate downsides. (Including, >> but not limited to, speed penalties, lots of code complexity, a >> tendency to be error-prone during development, and leakage of >> circular structures) On the upside, reference counting does get you >> deterministic destruction, but I don't usually consider that >> worthwhile enough to offset the downsides. > >It's not guaranteed deterministic destruction because of the cyclic >reference issue. Yep. Circular references are a big downside to refcounting, though as they're reasonably rare (though spawning horrid hacks like weak references) the expense is really the bigger issue. >Cyclic reference garbage is solved using a mark-and-sweep, is that how >you've solved it in Parrot? If so, reference counting means that you'll >probably get destruction when the object becomes unreachable from the root >set, but that may not always be the case. Yup, we do mark and sweep for objects. (We've actually split the search for dead objects apart from the compaction/collection of unused memory, but that's as much an implementation detail as anything else) > > It's possible to offset the lack of deterministic destruction if you >> require a sweep for dead objects at some regular time. (End of block >> time is a good one, as there's generally other cleanup that needs >> doing then) It's not a perfect offset, but doing that is awfully >> expensive. > >It basically boils down to: "Can the object be reached from the root set?" >Your right, thats too much to be doing too often. It's actually remarkably cheap, over the lifetime of a program, about half the expense of refcounting, IIRC. (Consider how many objects does your program *really* have active at any one time? Usually the answer's "Not many") >I like the sound of your closing paragraph and will adopt it's wisdom upon >failing to find a good solution. :-) Heh. When in doubt, punt and hope for the best. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk