Does variable = null set it for garbage collection

后端 未结 8 1471
走了就别回头了
走了就别回头了 2020-11-27 19:04

Help me settle a dispute with a coworker: Does setting a variable or collection to null in Java aid in garbage collection and reducing memory usage? If I have a long running

8条回答
  •  Happy的楠姐
    2020-11-27 19:27

    That's old performance lore. It was true back in 1.0 days, but the compiler and the JVM have been improved to eliminate the need (if ever there was one). This excellent IBM article gets into the details if you're interested: Java theory and practice: Garbage collection and performance

提交回复
热议问题