👤

when does a garbage collector collect garbage?

Sagot :

Answer:

As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.