Does it help GC to null local variables in Java

前端 未结 15 2055
旧巷少年郎
旧巷少年郎 2020-12-02 13:06

I was \'forced\' to add myLocalVar = null; statement into finally clause just before leaving method. Reason is to help GC. I was told I will get SMS\'s during n

15条回答
  •  感动是毒
    2020-12-02 13:48

    As you correctly point out, nulling out in this case is totally pointless.

    Back on JDK1.3 I did actually have a case with an extremely large object graph that also contained lots of circular references within the graph. Clearing out a few of the references did actually improve GC times quite noticeably.

    I am not sure if this would apply with a modern VM. Garbage collectors have become increasingly smarter.

提交回复
热议问题