Ephemerons meet OCaml GC, by François Bobot
Garbage collectors (GCs) manage the memory for the programmers and help to ensure the safety of the programs by freeing memory only when it cannot be used anymore. GCs detect that a memory block can’t be used when it is not reachable through pointers from memory blocks that are used. In order to allows the GC to free memory blocks and to avoid memory leaks, programmers must take care to not keep reachable any memory block which is not useful anymore. A difficulty arises when one wants to cache or memoize the computation of a function because one wants to keep the result as long as the argument and the function are used. In this presentation we call this the requirement. The first part of the presentation will show that it is not possible to find a general satisfactory solution for this problem with the current OCaml GC by going through tentative solutions with increasing complexity. Then we will present how the OCaml GC can be extended with ephemerons to solve the problem.