When to Garbage Collect

前端 未结 8 1222
逝去的感伤
逝去的感伤 2020-12-11 04:24

I have a piece of code that load a very big image in memory. So it seemed like a reasonable thing to call

System.gc();

before loading the

8条回答
  •  死守一世寂寞
    2020-12-11 04:41

    It's fine to call the garbage collector, you don't get any "problems" from it. However, I doubt it will significently boost performance, unless that call also deals with defragging the allocated data. I don't know that.

    What you should do in this case is profile the code. Run it several times, see what sort of results you get.

提交回复
热议问题