1

I am trying to get my Java code to run, but whenever I try the metaspace starts to get full. At first I didn't even notice it since it takes a long time (~1 month) to run full and crash.

The first thing I did was to look into the code, if there were Objects being created and filled with a lot of data and not deleted by the GC. After determining that this was (most likely) not the case I wrote a little test programm which results in the same error.

In my main I call a new TimerTask and assign a Timer to it. Afterwards I just schedule it.

TestTimer testTimerTask = new TestTimer();
Timer timer = new Timer("test");
timer.scheduleAtFixedRate(testTimerTask, 0, 100);

And here the TimerTask itself which just creates a bunch of Objects that should be deleted afterwards.

public class TestTimer extends TimerTask{
    private long x = 0;
    @Override
    public void run() {
        String str = "";
        for (int i = 0; i < 10000; i++) {
            if(x >= 2147483647) {
                x = 0;
            }
            str = new String("" + x);
            x++;
        }
    }
}

So I tried debugging it. For this I used the 2.0.4 Version of VisualVM. After letting it run for some time I got these two pictures of the Metaspace and the Heap.

In addition here's my JVM arguments,

-Xms64m
-Xmx128m
-Dlog4j.configurationFile=./log4j2.xml

my JVM Version OpenJDK 64-Bit Server VM (11.0.8+10, mixed mode) and my Java Version version 11.0.8, vendor Oracle Corporation.

Is there anything I can do to troubleshoot this problem some more and to stop my metaspace from filling up?

  • When your app crashed, are you getting `java.lang.OutOfMemoryError: Metaspace` or something else? – suv3ndu Nov 07 '20 at 16:05
  • @suv3ndu I stopped it before it did since there are other apps running on the same system. – Yuri Protector Nov 10 '20 at 17:27
  • Ok. In that case I will suggest you to follow [this answer](https://stackoverflow.com/a/37933050/5334745) to get the Metaspace data periodically. Once you have that, you can analyze them to see what's growing over time. – suv3ndu Nov 11 '20 at 15:10

0 Answers0