Profile Image
kamini mishra

When does garbage collection happen, between program start and program end?

I am not sure if garbage collection may actually happen after the program is done, that is after the process for your program is killed.
Or maybe ALL garbage collection is completed before the program ends?

  • garbagecollection

  • gc

Please Sign In or to post your comment or answer

Profile Image

Mahesh

The best thing about java garbage collection is that it's automatic. You don't have to do anything, unless you want and need to control and tune it. When the JVM will decide it's time to start reclaiming the space on the heap and throwing away unused objects it will just start the garbage collection process.

 

If you want to force the garbage collection you can use the System object from java.lang package and it's gc() method or Runtime.getRuntime().gc() method.

 

Note - It's considered a bad practice of calling garbage collection explicitly instead we should tune the work of garbage collector.

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • garbagecollection

  • gc