I’m developing a clojure application and it seemed to be using a lot more memory than it should. I thought it was a memory leak but after looking at it with jvisualvm it seems like the GC just isn’t running often enough. The red outlines are where I manually invoked the GC. Why is it allocating 300mb when it seems to be using around 30mb?
Make your heap smaller, if you think it’s too big. GC only runs when it has to.
(The controls have changed over the years, but I think they’re still in terms of an initial heap size, an increment size, and a max size. If your initial heap size is small, it will stay small so long as there’s no “high water mark” in heap usage that pushes it higher.)