Java VM - does the freed memory return to the OS?

前端 未结 2 1731
刺人心
刺人心 2020-12-12 02:02

In the Java runtime, if my application frees memory, does the runtime release the memory back to the OS? Or just back to my process?

2条回答
  •  有刺的猬
    2020-12-12 02:48

    Back to the process first, but also could go back to the OS in the end. Memory allocated by the GC is in a big contiguous chunk (the heap) or set of chunks, and GC "freeing" simply frees up the allocation in the heap, but not necessarily back to the OS. Once the GC compacts, it may be possible for the VM to return some memory to the OS.

    The GC wants to hold on to a certain amount of space so it can quickly service future "new" requests for memory. So GC makes requests to the OS for memory in large segments, as seldom as possible.

提交回复
热议问题