Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!ai-lab!life!tmb From: tmb@ai.mit.edu (Thomas M. Breuel) Newsgroups: comp.lang.c++ Subject: Re: reference counting vs. scanning GC Message-ID: Date: 24 Apr 91 22:15:37 GMT References: <1991Apr24.192424.23745@kestrel.edu> Sender: news@ai.mit.edu Organization: MIT Artificial Intelligence Lab Lines: 35 In-reply-to: gyro@kestrel.edu's message of 24 Apr 91 19:24:24 GMT In article <1991Apr24.192424.23745@kestrel.edu> gyro@kestrel.edu (Scott Layson Burson) writes: In article tmb@ai.mit.edu (Thomas M. Breuel) writes: >Such languages have the additional useful feature that those objects >for which reference counting makes sense can also never be circular, >which means that reference counting not only is the most efficient >garbage collection technique, but that it also is completely >sufficient. Reference counting will most likely also give you better >locality of reference as well, since recently freed objects are likely >to have been accessed recently as well. I must challenge the latter point. I guess you're referring to the fact that a garbage collection requires scanning many objects which may not have been touched recently, and that's true: the garbage collection process *itself* does not have very good locality. However, I think you are overlooking the fact that a well-designed generational garbage collector can make very important improvements in the locality of the objects as it relocates them, in such a way as to substantially improve the paging behavior of the application itself. This is true of compacting garbage collectors but is not relevant to the case I was discussing. I was talking about large heaps (many Mbytes) and large objects (about 1 Mbyte each or more). You cannot afford to compact (copy) such objects just because you might improve locality of reference (apart from the fact that compacting GC in C++ is tricky anyway). Compacting, generational, scanning garbage collectors are better than non-compacting reference counting garbage collectors for many allocation problems. However, for large monotype arrays, reference counting has lower overhead, and it is much simpler to implement than a solid generational scheme. Keep this in mind before you rush out to switch all your C++ memory management to a scanning garbage collector. Thomas.