Java: Why does this not get garbage collected?

前端 未结 4 1235
粉色の甜心
粉色の甜心 2021-01-03 18:39

Quick question about the theory of GCing. I have the following method. It runs, and exits the method. How come even after GC is run, the timer still exists and keeps \"TI

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 19:20

    How do you know the GC ran? Garbage collection in general is not a deterministic thing, and it's definitely not triggered by method scope. It's not like C++ where you leave scope of a function and destructors fire. It will get around to collecting that memory if and when the GC feels like it.

提交回复
热议问题