-2

no matter of how much memory I allocate 4, 8 or 10 Gigs, my app has a pattern of consuming most of the memory - 96% - and every few days comes to a halt as it does not have enough mem left to GC.

We are monitoring and triggering manual GCs to ease the pain, but I'd expect the JVM to anticipate this itself and GC in due course.

What flags should I consider to trigger GC at say 80% - and is this candid approach the right one?

3
  • 5
    You are taking the wrong path. Chase down the memory leaks instead of treating the symptoms.
    – Fildor
    Commented Jan 21, 2019 at 7:46
  • 1
    I would rather suggest you to generate a heap dump to analyze the memory leak problem Commented Jan 21, 2019 at 7:47
  • @NicolasB don't try to trigger the GC yourself. at most you can "request" it to run. But, deep down, the GC is bit of a douche. The GC itself will decide when to run, and even whether or not to run at all. You can't trigger it yourself, and be sure that it actually runs.
    – Stultuske
    Commented Jan 21, 2019 at 7:56

1 Answer 1

1

First check if you have:

StackOverFlowError is related to the stack:

Thrown when a stack overflow occurs because an application recurses too deeply.

OutOfMemoryError is related to the heap:

Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

If you have a StackOverFlowError is possible that you have a problem related to a recursion not finishing. So check your exit conditions to be sure that you have the right exit condition. Another possibility is to have two (or more) methods calling each other.

If you have an OutOfMemoryError you are probably storing to much objects in your memory. This happens for example if you store objects in a Map (for example using the map as a memory cache system) without removing them.

1
  • OutOfMemory: The bigger the objects the faster it will occurr. Had this problem with Images (really large ones) once. Coworker had written an "image-cache" but had a problem with references not being nulled, so the GC couldn't collect.
    – Fildor
    Commented Jan 21, 2019 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.