Hello! Ephemerons are not behaving exactly like I am expecting. Based on OCaml library : Ephemeron
The data is considered by the garbage collector alive if all the full keys are alive and if the ephemeron is alive. When one of the keys is not considered alive anymore by the GC, the data is emptied from the ephemeron. The data could be alive for another reason and in that case the GC will not free it, but the ephemeron will not hold the data anymore.
So if I understand that correctly then, if I create an ephemeron with a single key and a single value, then unset the key, the value should be considered to be ‘empty’. However this is not what I am observing, e.g.:
module E = Ephemeron.K1;;
let e = E.create ();;
let test () =
let k = "a" in
let d = 1 in
E.set_key e k;
E.set_data e d;
print_endline (string_of_bool (E.check_key e && E.check_data e)); (* true, OK *)
E.unset_key e;;
test ();;
E.check_key e;; (* false, OK *)
E.check_data e;; (* true, what?! *)
What I am trying to understand is how can the ephemeron’s data be considered ‘full’ or ‘alive’ if its key is empty?