From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA17529 for caml-redistribution; Wed, 24 Dec 1997 14:44:43 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA09900 for ; Tue, 23 Dec 1997 19:57:30 +0100 (MET) Received: from crotus.sc.intel.com (root@crotus.sc.intel.com [143.183.152.26]) by nez-perce.inria.fr (8.8.7/8.8.5) with ESMTP id TAA12923; Tue, 23 Dec 1997 19:57:26 +0100 (MET) Received: from mipos2.intel.com (mipos2-seg48.intel.com [143.183.48.42]) by crotus.sc.intel.com (8.8.6/8.8.5) with ESMTP id KAA13027; Tue, 23 Dec 1997 10:57:14 -0800 (PST) Received: from zws197.sc.intel.com (zws197.sc.intel.com [143.183.45.141]) by mipos2.intel.com (8.8.5/8.8.5) with ESMTP id KAA24248; Tue, 23 Dec 1997 10:57:11 -0800 (PST) Received: (from ctchou@localhost) by zws197.sc.intel.com (8.8.5/8.8.5) id KAA15696; Tue, 23 Dec 1997 10:57:07 -0800 (PST) Date: Tue, 23 Dec 1997 10:57:07 -0800 (PST) Message-Id: <199712231857.KAA15696@zws197.sc.intel.com> From: Ching-Tsun Chou To: caml-list@inria.fr CC: Pierre.Weis@inria.fr, doligez@pauillac.inria.fr Subject: What exactly can be GC'ed? Sender: weis 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 = # 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 = # 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 ========================================================================