Source

opycaml / tests / set_closure_string.ml

Full commit
open Opycaml.Api

let _ = Base.initialize ()

let m = Module.new_ "x"
let _ = Module.setToSys m "x" 

let _ = Format.eprintf "test start@."

let freed = ref 0
let finalize = fun _ -> incr freed

let f n = 
  let f = fun _args -> 
    Format.eprintf "f(%d)@." n;
    Object.obj (Base.none ())
  in
  Gc.finalise finalize f; 
  Module.setClosureString m "f" f;
  if n mod 1000 = 0 then begin
    Format.eprintf "*** %d@." n;
    Opycaml.Utils.Gc.report ();
    Format.eprintf "freed %d@." !freed
  end
;;

let _ = 
  for i = 0 to 100000 do
    f i
  done