Great answer! Thanks to you both. I have a followup ephemeron question which I'll post with a different subject. On Thu, Dec 20, 2018 at 1:46 AM Stephen Dolan wrote: > On Thu, 20 Dec 2018 at 00:30, Lindsay Errington < > lindsay.errington@gmail.com> wrote: > >> If however, I use the standalone bytecode compiler or the native compiler >> (4.07.1), then the entries are not nullified. Is this a bug or is there >> another way to persuade the garbage collector to clobber the entries? >> > > Thanks for the detailed example! > > The issue is with the test code at the end: > > let (root,map) = > let map = [] in > let (k0,map) = intern 0 (str 1) map in > let (k1,map) = intern 1 (Link k0) map in > let (k2,map) = intern 2 (Link k1) map in > (k2,map);; > > Fmt.printf "root=%a, map=@[%a@]@." pp_key root pp_map map;; > > let map = upd root (str 2) map;; > > Fmt.printf "root=%a map1=@[%a@]@." pp_key root pp_map map;; > > Both the bytecode and native code compilers take any value bound to a > global to be reachable forever, even if that global is later shadowed by > another global of the same name. The ephemerons don't get cleared, because > the original map is still alive. > > You can change the code to avoid putting the original map in a global > constant: > > let (root, map) = > let map = [] in > let (k0,map) = intern 0 (str 1) map in > let (k1,map) = intern 1 (Link k0) map in > let (k2,map) = intern 2 (Link k1) map in > Fmt.printf "root=%a, map=@[%a@]@." pp_key k2 pp_map map; > let map = upd k2 (str 2) map in > (k2, map);; > > Fmt.printf "root=%a map1=@[%a@]@." pp_key root pp_map map;; > > With this version, the original map becomes unreachable, so the GC can > clear the ephemerons. > > Stephen > -- Caml-list mailing list. Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list Forum: https://discuss.ocaml.org/ Bug reports: http://caml.inria.fr/bin/caml-bugs