Does it help GC to null local variables in Java

前端 未结 15 2054
旧巷少年郎
旧巷少年郎 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:50

    Another possible factor in this myth is that it can make a difference to null out a local variable if you are done with it before the end of the method. This would allow the GC to collect that object before the method is complete, which could be useful.

    Someone might have been given that advice at some point and misunderstood it as a need to always null out the local variables.

提交回复
热议问题