The best time to start the GC is "when the program has some time left". For example, if you have a run loop and no event has been queued, this might be the right time to start the GC. And then, perhaps, also, if the GC allocator notices that it will need to request the OS for more memory. I think it also depends on the design of the GC, for example. It is possible to create a GC that starts in its thread and does not interrupt the program compared to the usual GC "stop the world".
The question is also, do you want to implement the GC for training only? Or do you just want a GC? In a later case, I suggest you take a peek at GC Boehm.
source
share