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?