Does variable = null set it for garbage collection

后端 未结 8 1500
走了就别回头了
走了就别回头了 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条回答
  •  孤街浪徒
    2020-11-27 19:26

    It is a good to have. When you set objects to null, there is a possibility that the object can be garbage collected faster, in the immediate GC cycle. But there is no guaranteed mechanism to make an object garbage collected at a given time.

提交回复
热议问题