Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

  • 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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top