From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.misc:1389 comp.lang.modula2:742 comp.lang.ada:1097 Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!mailrus!tut.cis.ohio-state.edu!husc6!rice!titan!boehm From: boehm@titan.rice.edu (Hans Boehm) Newsgroups: comp.lang.misc,comp.lang.modula2,comp.lang.ada Subject: Re: Garbage Collection Summary: "answers" to questions on C garbage collection Message-ID: <634@ra.rice.edu> Date: 1 Apr 88 18:43:44 GMT References: <145@krafla.rhi.hi.is> <272@fang.ATT.COM> <429@zap.UUCP> <8196@sol.ARPA> <628@ra.rice.edu> <26358@cca.CCA.COM> <632@ra.rice.edu> <26413@cca.CCA.COM> Sender: usenet@rice.edu Reply-To: boehm@titan.rice.edu (Hans Boehm) Organization: Rice University, Houston List-Id: Richard Harter writes: >I still don't see how a garbage collector helps with premature deallocation, >unless you scrap deallocation entirely, and rely entirely on garbage >collection. >The problem with garbage collectors in the old days was that they did >garbage collection when the available space was allocated. This works >well enough until the actual amount of space allocated starts to approach >the amount of available space, and then the garbage collector starts >thrashing. Is this a problem? If not, how do you deal with it? Our current version of the collector doesn't help you with premature deallocation. Further instrumenting it might help. For example, you could use the marking algorithm to determine whether "free"d objects really were inaccessible. (This requires a coding style in which unused references are explicitly cleared. Replacing "free" by a macro that clears its argument takes care of a lot of that and, by itself, occasionally helps track down bugs.) I don't have much experience with this though. In non-real-time applications, we tend to use explicit deallocation where it's easy to do, and let the collector take care of the error-prone cases. You are right in that the garbage collector code is not completely portable. It should really be viewed as part of the run-time library, which is rarely completely portable anyway. Actually porting it isn't terribly hard. There is only about a screenful of machine dependent code in the collector. The longest part of that deals with marking from the machine registers. Frequent collections in small address spaces can become a problem. We operate in a virtual memory environment, so we deal with it by expanding the heap size whenever a collection fails to return enough memory. This requires allocating a bit of extra memory. For debugging, this hardly matters. (Memory is supposedly cheap.) In a production environment, especially without virtual memory, it could be a problem. On the other hand, for some existing code, this can be much less significant than memory otherwise lost to leaks. Hans-J. Boehm (boehm@rice.edu)