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

有帮助吗?

解决方案

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.

其他提示

  • 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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top