-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Memory leak when using threads #11289
Copy link
Copy link
Closed
Description
This bug has been tested with OCaml 4.13.0. I am in the process of testing it with 5.0.0 (on a m1 mac)
The following program:
let rec f () =
let th = Thread.create (fun () ->
let b = Bytes.make (10*4096) ' ' in
Printf.printf "New Thread with %d bytes\n%!" (Bytes.length b);
Unix.sleepf 0.1) ()
in
Thread.join th;
f ()
let () = f ()Seems to leave the memory allocated in the thread for too long. In my test, the program quickly rose to ~60Mo of RAM within minutes:

The same program with a call to full_major does not exhibit the issue:
let rec f () =
let th = Thread.create (fun () ->
let b = Bytes.make (10*4096) ' ' in
Printf.printf "New Thread with %d bytes\n%!" (Bytes.length b);
Unix.sleepf 0.1) ()
in
Thread.join th;
Gc.full_major();
f ()
let () = f ()This seems to indicate that the GC is underestimating the amount of memory waiting to be cleaned up from the thread's allocations.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
