Does it help GC to null local variables in Java

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

    There was an old piece of Sun documentation, Java Platform Performance (link sadly now broken, and I haven't been able to find a new one), which described a situation where nulling a local variable which dropped out of scope actually had an effect on the GC.

    However, the paper referred to a very old version of java. As mentioned in this question (which also contains a précis of the problem described in the paper), this no longer affects current JVM implementations.

提交回复
热议问题