Just as a point of interest, I believe there are special forms of garbage collector that are suitable for hard real time systems.
The principle is to regularly use a bounded amount of time for collecting - in line with the latency requirements for the whole system. I think the relevant term is 'tick tock', as in tick - compute, tock - collect.