Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!ux1.cso.uiuc.edu!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.sw.components Subject: Component with garbage collection Message-ID: <130200012@p.cs.uiuc.edu> Date: 26 Sep 89 23:20:57 GMT Lines: 26 Nf-ID: #N:p.cs.uiuc.edu:130200012:000:1367 Nf-From: p.cs.uiuc.edu!johnson Sep 25 21:39:00 1989 I'm building a compiler with a complex type system. There is an abstract data type "type" that describes the various kinds of types. There are only a few public operations on types, but there are many private operations that are used to implement the public operations. Types are immutable values, so it should be fairly easy to manage their storage by hand. However, types take up a significant percentage of memory, so we work hard to have different types share structure. This works well because they are immutable. However, sharing structure means that deleting type T will not necessarily delete the components of T. This might seem like a good place to use reference counts, but unfortunately types are circular structures. Thus, there is really no alternative but garbage collection. We could avoid garbage collection by not sharing structure. This would add a megabyte to the amount of memory needed to run our programs. Moreover, since the compiler doesn't work all that well, we only compile small programs. It is hard to tell how much memory structure sharing would save on a large program, but I bet it would be a lot. If I were programming this in C++ then I would write the type module to collect its own garbage. However, this would certainly be no faster and would be a lot more error-prone than automatic garbage collection. Ralph Johnson