Java process memory usage keeps increasing infinitely

后端 未结 3 646
既然无缘
既然无缘 2021-02-05 07:58

Preconditions:

  • PC with 16 Gb of RAM
  • JDK 1.8.x installed on Ubuntu 16.10 x64.
  • a standard Spring-based web application, that is deployed on Tomcat
3条回答
  •  半阙折子戏
    2021-02-05 08:19

    Can you rerun your tests with this option -XX:MaxDirectMemorySize=1024m? The exact value of this limit does not matter, but it shows possible "leaks".

    Can you also provide GC details (-XX:+PrintGC)?

    java.nio.ByteBuffer is a possible cause of them due to it specific finalization.

    UPDATE #1

    I have seen similar behavior for two another reasons: java.misc.Unsafe (unlikely) and high-loaded JNI-calls.

    It is hard to understand without profile of the test.

    UPDATE #2

    Both high-loaded JNI-calls and finalize() method cause the described problem since objects do not have enough time to finalize.

    The j.u.zip.Inflater fragment below:

    /**
     * Closes the decompressor when garbage is collected.
     */
    protected void finalize() {
        end();
    }
    
    /**
     * Closes the decompressor and discards any unprocessed input.
     * This method should be called when the decompressor is no longer
     * being used, but will also be called automatically by the finalize()
     * method. Once this method is called, the behavior of the Inflater
     * object is undefined.
     */
    public void end() {
        synchronized (zsRef) {
            long addr = zsRef.address();
            zsRef.clear();
            if (addr != 0) {
                end(addr);
                buf = null;
            }
        }
    }
    
    private native static void end(long addr);
    

提交回复
热议问题