Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Basile.Starynkevitch@cea.fr (STARYNKEVITCH Basile)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: GC with finalisation?
Date: Sat, 28 Aug 1999 22:49:30 +0100 (MET DST)	[thread overview]
Message-ID: <199908282049.WAA13305@miss.wu-wien.ac.at> (raw)
In-Reply-To: <14278.15024.193052.853437@gargle.gargle.HOWL> from "STARYNKEVITCH Basile" at Aug 27, 99 09:13:52 am

> On the other hand, I consider that finalized objects supported by the
> language (such as provided by Java & Python) are a mistake. In my
> opinion, finalized objects should not have a user-provided finalizer,
> but should only deal with system resources (file descriptors, X11
> windows, coded only in C)

I once asked for finalizers (for objects) in this list, but I was pointed
to problems which I hadn't thought about: for example, user defined
finalizers might place the object to be reclaimed in a (global) reference
again - what is the garbage collector supposed to do in such cases?
Other kinds of side effects (eg. calling methods of other objects)
could lead to similar problems.

Another argument against finalization is the following: if your program
enters a very time-consuming loop in which it doesn't allocate anything,
the garbage collector will not be called and the finalization of
values/objects might be delayed for a long time.

Actually, this is even a problem in languages with stack allocated values:
as long as the value is not out of scope, the destructor will not be
called (unless the compiler manages to see that the object can be safely
finalized and deallocated earlier - which is probably more than tough).

Concurrent environments (eg. when doing network communication) may be
adversly effected by such delays.

Developers of libraries have no control about this, because this problem
depends on the way the programmer makes use of values/objects.

There are other means to "finalize" values: instead of using
destructors/finalizers, you could provide for higher-order functions
that do the job.

Eg. you want that a network connection is opened, used in some way and
closed again (but immediately!). This could look as follows:

let do_connection f =
  let con = open_connection (...) in
  f con;
  close_connection con

If you provide only such functions to the user, he doesn't have to care
about closing connections or do some other finalization and he still
has the guarantee that connections are closed immediately - which might
allow the server on the other side of the connection to do something
more useful than wait...

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




  parent reply	other threads:[~1999-08-30 13:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-24  3:36 John Skaller
1999-08-26 21:09 ` Markus Mottl
1999-08-27  5:10   ` John Skaller
1999-08-27  7:13 ` STARYNKEVITCH Basile
1999-08-28  4:29   ` John Skaller
1999-08-28 21:49   ` Markus Mottl [this message]
     [not found] <3.0.6.32.19990830144523.00964e20@mail.triode.net.au>
1999-08-30 12:31 ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199908282049.WAA13305@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=Basile.Starynkevitch@cea.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox