From ecd778d5d92dc7cd0b57b9eb78b509ab851f3474 Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Sat, 10 Oct 2026 00:32:21 +0000 Subject: The finalizer should also release the handle --- lib/protocols/Handle.ml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/protocols/Handle.ml') diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml index 7f7fe95..fc226c0 100644 --- a/lib/protocols/Handle.ml +++ b/lib/protocols/Handle.ml @@ -26,6 +26,11 @@ let object_of {valid; refers_to; _} = let to_string h = let o = (object_of h) in "#<" ^ o#to_string ^ " " ^ (Concepts.Hash.to_hum_string o#hash) ^ ">" +let release ({valid; _} as handle) = + let o = object_of handle in + if Atomic.compare_and_set valid true false then + o#release + let on_gc ({valid; refers_to; allocated_at} as h) = (* TODO: get rid of this on release builds *) if refers_to#is_managed && (Atomic.get valid) then begin @@ -34,14 +39,10 @@ let on_gc ({valid; refers_to; allocated_at} as h) = (* bleh *) ~str:(Printexc.raw_backtrace_to_string allocated_at) ~sub:"Raised by primitive operation" - ~by:"Allocated")) + ~by:"Allocated")); + release h end -let release ({valid; _} as handle) = - let o = object_of handle in - if Atomic.compare_and_set valid true false then - o#release - type _ Effect.t += Autorelease: t -> unit Effect.t let with_autorelease f = -- cgit v1.2.3