From: Ching-Tsun Chou <ctchou@mipos2.intel.com>
To: caml-list@inria.fr
Cc: Pierre.Weis@inria.fr, doligez@pauillac.inria.fr
Subject: What exactly can be GC'ed?
Date: Tue, 23 Dec 1997 10:57:07 -0800 (PST) [thread overview]
Message-ID: <199712231857.KAA15696@zws197.sc.intel.com> (raw)
I sent a message to caml-list asking what weak pointers are. Pierre
Weis kindly pointed out that they had been extensively discussed in
caml-list. I read those messages and realized that my question is
really about garbage collection (GC): What exactly can be GC'ed?
Consider the following O'Caml session:
------------------------------------------------------------------------
# let x = ref (String.make 3 'a') ;;
val x : string ref = {contents="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"
# x := "bbb" ;;
- : unit = ()
# Gc.full_major () ;;
- : unit = ()
# Weak.get w 0 ;;
- : string option = None
------------------------------------------------------------------------
As expected, the string "aaa" is GC'ed.
Now, consider the following (fresh) O'Caml session:
------------------------------------------------------------------------
# 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?
I should mention that I'm using O'Caml v.1.05.
- Ching Tsun
========================================================================
Ching-Tsun Chou E-mail: ctchou@mipos2.intel.com
Intel Corporation, RN6-16 Tel: (408) 765-5468
2200 Mission College Blvd. Fax: (408) 653-7933
Santa Clara, CA 95052, U.S.A. Sec: (408) 653-8849
========================================================================
next reply other threads:[~1997-12-24 13:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-12-23 18:57 Ching-Tsun Chou [this message]
1997-12-27 13:37 Damien Doligez
1998-01-06 0:03 Ching-Tsun Chou
1998-01-06 13:28 Damien Doligez
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=199712231857.KAA15696@zws197.sc.intel.com \
--to=ctchou@mipos2.intel.com \
--cc=Pierre.Weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=doligez@pauillac.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