
Patrick B. answered 08/03/19
Math and computer tutor/teacher
well one place where the garbage collection unit is activated is when a subroutine or function returns and the local vars and parameters go out of scope. This happens when the procedure call pops off the call stack.
Although this is done more on the O.S. side, the O.S. executing the program will have to invoke the garbage collector and passing the addresses of the parameters and the local vars...which in turn get replaced onto the stack and the heap respectively...
In Java, the JVM handles the garbage collection, although the programmer does not have complete control over it. There are destructor like calls that can alert the JVM hand the objects over to GC, but does not guarantee it.