Re: memory management and productivity

From: Robert I. Eachus (rieachus_at_comcast.net)
Date: 06/26/04


Date: Sat, 26 Jun 2004 11:44:33 -0400

Ole-Hjalmar Kristensen wrote:

> Well, perhaps, but what Jano described is exactly like C++.
> Doesn't the automatic finalization of an access to a controlled
> object happen only when the *type* goes out of scope?

No, as Martin's program shows, finalization occurs when the object or
the type can no longer be referenced, no matter how that happens. This
means you have to be a bit careful in designing your Finalize procedure.
  It may be called several times on the same object in complex cases.
(The rule is that controlled objects in Ada are always finalized at
least once. If you think about a subprogram that is doing clean-up when
an exception occurs, you can see why the choice is between at least once
and almost always.)

But writing Finalize so that it is okay to call it multiple times is
usually easy enough to do. Deallocating an object sets the pointer to
it to null, and doesn't complain if given a null pointer as an argument.

-- 
                                           Robert I. Eachus
"Reason and experience both forbid us to expect that national morality 
can prevail in exclusion of religious principles." -- George Washington


Relevant Pages

  • Re: portable finalizer
    ... finalization in SBCL, but I want to make my code portable. ... is a pointer to a C structure. ... so there is a destroy method: ... object destroyed when it is garbage collected. ...
    (comp.lang.lisp)
  • Re: Class Instantiation Question
    ... But there is more to finalization than this. ... then a pointer to the object is placed on the finalization queue. ... The garbage collector scans the finalization queue looking for pointers to these objects. ... is removed from the finalization queue and appended to the freachable queue. ...
    (microsoft.public.vb.general.discussion)

Loading