1

I have a desktop application which is 'kinda' memory hungry, always performing background tasks every 15 seconds. When analyzing it through JVisualVM, the used heap is around 60mb right after every garbage collection and about 210mb right before GC, though it can increase if the app is used very often. The heap size is always around 380/400mb. This pretty much stays the same all the time, at least when analyzing the application in my local machine.

The problem is, in some clients, in rare occasions, the system hangs because apparently the OS don't have enough memory to itself, because it's used in the heap (even if not used by the application itself).

So, in a 4gb machine, when the OS itself and another apps consume about 2gb, when using two or three instances of the app can easily cause the memory usage to go up to 95%, this is where i think it is hanging the OS.

Is there a way to make the heap size be just what the app needs? Or am i talking BS and the problem is happening for some other reason?

Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101
  • A 95% RAM usage should not hang the OS. Especially with the usage pattern you described - if the app becomes relatively memory-hungry once every 15 seconds. You *could* set a hard limit on heap memory via JVM options, but I'd say that won't cure the original problem. Does the target machine have memory swap enabled? (Some "smart" sysadmins disable this option to "extend SSD life, since there's enough RAM anyway") – Ordous Mar 09 '16 at 15:12

1 Answers1

1

You can try to set the limit on the heap smaller. This will force the garbage collector to act but will make the memory foot print of your programs smaller.

There is a question here in SO with information on how to set that.

Community
  • 1
  • 1
gfelisberto
  • 1,655
  • 11
  • 18
  • Yeah but if i decrease the maximum heap size, even if i set it higher than the average RAM usage of my app, i can get an OutOfMemoryError because sometimes, due to user operations, the memory usage can increase shortly. – Mateus Viccari Mar 09 '16 at 17:58