Question

I read somewhere that Garbage collection is not like destruction(in the C++ sense). how they are different?

Was it helpful?

Solution

C++ destruction is deterministic, garbage collection is not.

In C++ you can guarantee when destructors will be called, in Java there is no such guarantee at all. In fact, your destructors might never be called in Java.

OTHER TIPS

  • Destructor is called before an object is about to be deleted (Whether it is on the stack or heap)
  • Garbage collection will go through your program every now and then checking to see if there are any variables that are no longer being used and delete them
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top