Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

  • 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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top