[comp.lang.c++] garbage collection arguments

chase@Ozona.orc.olivetti.com (David Chase) (08/03/89)

>>In article <779@redsox.bsw.com> campbell@redsox.UUCP (Larry Campbell) writes:
>>>Modula-3, by contrast, allows you to decide on a type-by-type basis whether
>>>objects of the type are to be GC'd or not.  This seems to me to be the best
>>>solution.

>In article <45901@oliveb.olivetti.com>, chase@Ozona.orc.olivetti.com (David Chase) writes...
>> [only in unsafe code]

In article <3917@shlump.nac.dec.com> nadkarni@ashok.dec.com writes:
>Not true as far as I recall. If I remember the report correctly, you CAN decide
>on a type by type basis whether to GC or not. The UNTRACED keyword is provided
>for this purpose. This is true even for SAFE modules. What you might be
>referring to is that untraced REFs can point to traced REFs (or is it the other
>way around ?) only in UNSAFE modules.

Strictly speaking, you are correct.  However, the DISPOSE statement is
only allowed in UNSAFE modules.  That is, it is "safe" to allocate
non-collectable storage, but unsafe to free it.  Lucky you.

You *can* defeat this by suitable trickiness; an UNSAFE module can
export a SAFE interface to the routine

  PROCEDURE My_sneaky_dispose(x:ADDRESS) RAISES {} = 
  BEGIN
    DISPOSE(x)
  END My_sneaky_dispose;

but you cannot possibly prove this code correct, since there is no way
that it can be guaranteed that this is the last reference to x.  Thus,
a programmer has no business whatsoever exporting this procedure in a
SAFE interface.  In practice, if you use an UNTRACED REF and which to
ever reclaim that storage (correctly), you'll need to hide it within
an opaque type so that clients cannot make their own private copies of
it.  (This is made much easier in the second version of the language.)

Sorry for the digression, but I'm a big fan of truth-in-advertising.
I wouldn't want a bunch of C and C++ hackers to get fired up about
Modula-3 because of this alleged feature only to get pissed off when
they discover that they can't FREE any of that memory that they
allocated.  If you're interested in information hiding, garbage
collection, exception handling, threads, and a certain style of
object-orientedness (similar to that in C++, I think), then perhaps
you should check out Modula-3, but don't think that it will solve
*this* problem for you.

David