[Prev][Next][Index][Thread]

Re: Object lifetime management



Brad Settlemyer <nobody@nowhere.com> writes:

> C++ has a powerful idiom to leverage the consistency of polymorphic
> destructors (Smart pointers), that imo are at least as effective as
> java's gc at memory management (I'm still trying to find some
> documentation that describes the standard dylan memory mgr).

How do smart pointers handle circuclar references?

  class parent
  {
  public:
    counted_pointer<child> child;
  };

  class child
  {
  public:
    counted_pointer<parent> parent;
  };

A GC handles this structure with ease.

Note that C++ does not have smart pointers as part of the standard. It
has auto_pointer which is not quite smart. It does not do reference
counting for example. If I recall correctly, a std::vector of
auto_ptr is a recipe for disaster.

What C++ does have is an idiom for smart pointers and lots of
implementations of these by various people. No different from Dylan
having different implementations of ways to handle resource
acquisition and release via with-* macros.

> I think Dylan has made a mistake in not addressing this issue, but I
> am still a newby at this language (less than a newby even), and I
> still want to see what other benefits it offers.

What types of things do you see using destructors for that can't be
done via with-* macros? Remember that you still need to write a class
to acquire a resource in a constructor and release it in a
destructor. No different from writing a macro to do the same. 

Note that I'm not trying to start a c++ vs. Dylan language
argument. I'm genuinely interested in how you'd use a C++ destructor
that with-* or the like doesn't solve so possible Dylan solutions can
be presented.

Chris.
-- 
http://www.double.co.nz/dylan



References: