caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <Damien.Doligez@inria.fr>
To: caml-list@inria.fr
Subject: Re:  What exactly can be GC'ed?
Date: Sat, 27 Dec 1997 14:37:52 +0100	[thread overview]
Message-ID: <199712271337.OAA10772@tobago.inria.fr> (raw)

>From: Ching-Tsun Chou <ctchou@mipos2.intel.com>

># let x = String.make 3 'a' ;;
>val x : string = "aaa"
># let w = Weak.create 1 ;;
>val w : '_a Weak.t = <abstr>
># Weak.set w 0 (Some (x)) ;;
>- : unit = ()
># Weak.get w 0 ;;
>- : string option = Some "aaa"
># let x = "bbb" ;;
>val x : string = "bbb"
># Gc.full_major () ;;
>- : unit = ()
># Weak.get w 0 ;;
>- : string option = Some "aaa"

>It seems to me that since x has been re-bound to "bbb", its old value
>"aaa" is no longer reachable and hence can be GC'ed.  But clearly I
>was wrong.  Where did I go wrong?  What exactly can be GC'ed?

Caml is a language with static binding.  The new definition of x does
not replace the old one in any way, except in the table that maps
names to slots in the table of globals.  When you define the second x,
the first one only loses its name.  It still exists as a global
variable.

Assume that you insert "let f () = x;;" anywhere between the two
bindings of x.  Then the old value is still reachable through f.

The compiler does not recycle globals table entries because it would
add useless complexity to the system (to determine whether an entry is
still in use or not), and it only makes sense under the toplevel
system, which is mostly intended for debugging anyway.

-- Damien





             reply	other threads:[~1997-12-29  8:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-27 13:37 Damien Doligez [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-01-06 13:28 Damien Doligez
1998-01-06  0:03 Ching-Tsun Chou
1997-12-23 18:57 Ching-Tsun Chou

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=199712271337.OAA10772@tobago.inria.fr \
    --to=damien.doligez@inria.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;
as well as URLs for NNTP newsgroup(s).