Path: utzoo!attcan!uunet!snorkelwacker!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.object Subject: Re: C++ and garbage collection Message-ID: <1990Sep19.114445.25042@tukki.jyu.fi> Date: 19 Sep 90 11:44:45 GMT References: <1990Sep16.090226.11051@tukki.jyu.fi> <1990Sep18.131307.984@tukki.jyu.fi> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 74 In article <1990Sep18.131307.984@tukki.jyu.fi> I wrote: >In article pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: >> ... >>The definition of "in use" being that its address as if returned by the >>storage allocator appears in one or more pointers in storage. If you are >>using any other definition of "in use" you are making your own rules, >>and we are no longer speaking of storage allocation or reclamation as is >>described in the current academic literature on the subject. > >Aha, we have been playing with different rules. > ... >In fact, I am afraid that the above rule would not allow completely >safe GC to be implemented even for Pascal, although its pointer >handling is so much more restricted. (I can try to construct >an example if requested.) > ... To the disappoinment of all readers, here is an example although I have not been requested: type bucket = record ... end; pail = ... ; container = record first: pail; second: bucket; third: ... end; var mystore: ^container; procedure doit (var vessel: bucket); var ... ; begin mystore := nil; ... end; begin mystore := new (container); doit (mystore^.second); ... After the assignment statement in 'doit' has been executed, there is nowhere a pointer as returned by the storage allocator, yet the 'second' part of the allocated record is in use to the end of the procedure. (This example can be easily rewritten in C or C++.) Another example is still a little simpler, but I am not 100% sure about if it is legal standard Pascal. (There is no C or C++ equivalent.) Assuming the same type and variable definitions as above: begin mystore := new (container); with mystore^.second do begin mystore := nil; ... (* references to components of 'bucket' can be used here *) end; ... BTW, now the mouse is already chasing the cat. I originally claimed that garbage collection is not applicable to C++ (generally). Piercarlo Grandi disagreed, and we had some rounds of dispute. In his last posting, he presented the rule quoted above; it is very evident that C++ does not qualify for GC according to it, but I protested that the rule was too strict. Why do I want to prevent him from shooting his own foot? Markku Sakkinen Department of Computer Science and Information Systems University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)