Search code examples
javac++garbage-collectiondestruction

What is the difference between Java Garbage collection and C++ object destruction?


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


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.