Java garbage collection

前端 未结 7 2153
生来不讨喜
生来不讨喜 2020-12-05 09:44

Java automatically calls garbage collector, then why we need manual calls for garbage collection? When should use System.gc()

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 10:14

    Garbage collection process is not under the user's control.So it makes no sense to call System.gc(); explicitly. It entirely depends on the JVM.

    Few days back, I had asked exactly the same question : [Here].

    In fact, many questions related to calling System.gc(); explicitly have been already asked and answered here. Calling System.gc(); explicitly is always considered as poor programming skill, although it won't do any harm.

    Here are the few links that I you should go through it. It will definitely clarify your doubt.

    • Calling System.gc(); explicitly
    • Bad practise - Calling System.gc();
    • System.gc(); in java

    PS : Btw, you should seriously take the extra effort to go through similar StackOverflow questions before posting about your doubts.

提交回复
热议问题