Burst memory usage in Java

前端 未结 8 2191
臣服心动
臣服心动 2021-02-03 23:57

I am trying to get a handle on proper memory usage and garbage collection in Java. I\'m not a novice programmer by any means, but it always seems to me that once Java touches so

8条回答
  •  误落风尘
    2021-02-04 00:26

    A common misconception is that Java uses up memory as it runs and there for it should be able to return memory to the OS. Actually the Oracle/Sun JVM reserves the virtual memory as a continuous block of memory as soon as it starts. If the isn't enough continuous virtual memory available it fails on start up even if the program isn't going to use that much.

    What then happens is the OS is smart enough not to allocate physical memory to the program until it is used. It cannot easily reclaim the memory but it can be swapped to disk if it needs to and it hasn't been used for a while. Java doesn't handle having parts of the heap swapped to disk very well so this should be avoided.

提交回复
热议问题