且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在匿名类中使用最终变量时的垃圾收集

更新时间:2022-11-23 16:12:39

o might get garbage collected once it is not reachable any longer, whether it is final or not. Obviously, as long as execute is running, if it needs to access o, it will prevent GC.

When execute is done running, and assuming you have not stored any references to o (for example in a collection), it will be flagged as ready for garbage collection.