GC recovers memory to the JVM. it will run when the JVM thinks it needs to. if your program dies, all that memory is restored to the operating system.
You can think of memory as an office building. The OS owns the whole thing. The JVM is a tenant, who may rent a couple of floors. The OS doesn't care how the tenant uses the memory, it just knows that nobody else can have floor 3-5.
Then, the JVM decides how to divide up the floors it owns. as people start working there (i.e. object created), the tenant/jvm decides what cube they should go in. Some people will quit the company. eventually, they may need to re-arrange everyone on the floors. None of this matter to the OS.
When the JVM 'breaks its lease', all the memory is returned to the OS/landlord, who can then rent it to someone else.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Dec 26, 2010
Thanks a lot for the clear and precise explanation.
That clears all my doubts