简体   繁体   中英

How does Java reserve/use memory?

This is probably a noob question, but I need to run a java application processing a large dataset. So I went about -Xmx14G, knowing that my machine has 16G of physical memory.

A short while later, boom, I am being notified by my operating system that my startup disk is almost full. I checked my process, there's no OOM exception, just that it stalled. Checked my activity monitor, doesn't says the application runs at full memory capacity.

How does the JVM reserves/use memory?

Typically, the JVM allocates new memory until the heap is full, in which case it garbage collects, freeing up non-referenced objects. If you allocated 14GB for the heap, chances are it will consume that much memory.

There is another JVM argument -Xms<size> it' initial heap size. If we do not set it explicitly JVM will choose one automatically depending on PC configuration. This value is never that big, typically 64M. Later JVM may allocate more memory up to max. But it happens only when the app really uses it. If actual memory usage decreases JVM will shrink the memory to a smaller size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM