Geek
Geek

Reputation: 23419

Java Process taking more and more memory

All,

I have a Java Memory Process which starts to take more and more memory with time. To put a Cap on the heap space usage I set -Xmx option to 512M. Slowly over a period of time the Process memory usage reached 2GB.

I have analyzed the code for possible memory leaks using various tools like MAT and YOURKIT and found no such possible leaks in the Java code. The code also makes use of One Native function which looks leak free.

I have the following questions :

  1. Is it possible to cause an upper limit on the total memory a Java Process can use ?
  2. What are the other memory usages of the JVM apart from the Heap ?
  3. Does Linux work on 'Working set' memory model of Windows where a process when put into background releases it's memory.
  4. Even after using -Xmx option with 512M shouldn't the JVM throw an 'Out Of memory' if the heap usage increases. This makes me suspect that the memory is being leaked by something else apart from the Heap space. From the memory dumps it seems that the Heap Memory is not increasing.

thanks for the answer.

Upvotes: 0

Views: 3477

Answers (3)

Nikem
Nikem

Reputation: 5784

If you suspect memory leak in your java application, you should definitely try Plumbr. It is quite good and spotting them and gives quite useful reports.

Upvotes: 1

paulsm4
paulsm4

Reputation: 121649

Let me augment my "comment" with a full-fledged "response".

If you're doing a lot of string manipulation, you should definitely not be using the "String" class. And whatever's going on, Java has many great tools (including, but not limited to, JConsole) that let you intelligently analyze the problem. Your Two New BFFs should be:

  • StringBuilder (manipulate strings efficiently) and

  • JConsole (study your program's behavior; including heap allocation and garbage collection).

And, as user643011 correctly pointed out, there are lots of other things that might conceivably "leak": including files not being closed, lots of threads using lots of stack space, etc. etc.

Here is one other good link:

Upvotes: 1

user643011
user643011

Reputation: 2393

How are you measuring memory usage?

Usually there are 3 kinds of memory usage:

  • VIRT -- Virtual Memory Size (KiB) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
  • RES -- Resident Memory Size (KiB) The non-swapped physical memory a task has used.
  • SHR -- Shared Memory Size (KiB) It simply reflects memory that could be potentially shared with other processes.

The virtual memory size can become larger (several GB) than what you specified with -Xmx, but this does not do any harm. RES plus SHR is what you should be looking at.

Apart from the heap there is another class of memory usage not affected by -Xmx (permgen). But that is usually capped at a few MB. You might want to read the HotSpot GC Tuning Guide.

Upvotes: 5

Related Questions