I'm trying to process a large dataset in java, and so I set my -Xmx11G.

1 thing I observed is, when I use xmx and the Jvm starts, the amount of inactive memory jumps up by about that much. Later, I see my swap file jumps up, but my inactive memory still has about 7gb left. Why is the os not utilizing the inactive memory but insteads swap out to disk???

  • Which OS Mavericks has changed the memory set up also what memory does Activity monitor show java as using?
    – mmmmmm
    Jan 28, 2014 at 15:23
  • mountain lion dude
    – goh
    Jan 29, 2014 at 3:13

1 Answer 1


The general answer is that Java's pattern of memory usage differs from other apps as it uses garbage collection in a fixed size memory thus getting all the memory it might use up front rather than getting it when it is needed..

The start is the JVM allocating the memory, then I think its garbage collection tends to access the memory often or else you have allocated the large Java dataset and only accessing part of it. Thus the 11G of memory is accessed but not often enough to be marked as active. A C based program won't have a background thread looking at all the pages of memory so pages can be inactive long enough to be swapped out.

From experience albeit on other OSs Java really slows down if any of its memory is swapped and you adjust the size of its VM so it does not. If you need more memory then get more RAM or alter the algorithm to use less.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .