title: Find native memory leak in Java application using JeMalloc
body: <p>Currently I am trying to resolve a Java memory issue: 
  My Java application keeps using more and more memory and 
  eventually it gets killed by the Linux OOM killer.</p>
  
  <p>There is probably a Native Memory leak, because after inspection 
  of the JVM with VisualVM both metaspace and the heap look OK.</p>
  
  <p>Using the top command I can see that the memory used by the JVM 
  keeps on increasing. </p>
  
  <p>The first graphic in this article:</p>
  
  <p><a href="https://plumbr.io/blog/memory-leaks/native-memory-leak-example" rel="noreferrer">Example #1</a></p>
  
  <p>Is a perfect match of what I am seeing in my own application.</p>
  
  <p>So I tried using JeMalloc to find the leak as described in various articles.
  Here I run into a problem: When using the jeprof command and later 
  the top command in jeprof itself, it does show the functions that use 
  the most memory, but these are in hexadecimal addresses, so I must 
  be missing some symbols. But I do not know which packages I need for that, that is unknown to me.</p>
  
  <p>I already found this link:
  <a href="https://stackoverflow.com/questions/48250864/jvm-findsignal-function-continuously-allocates-native-memory">Link #1</a></p>
  
  <p>And installed this package:
  debuginfo-install java-1.8.0-openjdk</p>
  
  <p>I tried to work through simple steps first:</p>
  
  <p>Get JeMalloc to work with a simple application, such as w.
  Next get it to work with java -version.
  So far so good, I can also get PDF's from JeMalloc with a perfect overview.</p>
  
  <p>Next get it to work with java -jar simpletest.jar &lt;&lt; Here I am missing symbols
  For example, if I do not close a GZipInputStream here, that does not show up in the JeMalloc results.</p>
  
  <p>Next get it to work with java -jar myapplication.jar &lt;&lt; Here I am missing symbols as well.</p>
  
  <p>So my question is basically:
  What packages do I need in order to get JeMalloc to display all symbol-names to debug applications such as:</p>
  
  <pre><code>public void test1() {
      InputStream fileInputStream = null;
      GZipInputStream gzipInputStream = null;
  
      try {
        fileInputStream = new FileInputStream("test.zip");
        gzipInputStream = new GZIPInputStream(fileInputStream);
  
        int data = gzipInputStream.read();
        while (data != -1) {
          // do something with data
          data = gzipInputStream.read();
        }
  
      } catch (Exception ex) {
  
      } finally {
        // Disabled to see whether JeMalloc can detect the leak
        /*try {
          if (gzipInputStream != null) {
            gzipInputStream.close();
          }
          if (fileInputStream != null) {
            fileInputStream.close();
          }
  
          gzipInputStream = null;
          fileInputStream = null;
        } catch (IOException e) {
        e.printStackTrace();
      }*/
    }
  }
  </code></pre>
  
  <p>Using the following software:</p>
  
  <ul>
  <li>Linux CentOS 7</li>
  <li>JeMalloc</li>
  <li>OpenJDK</li>
  </ul>
  
  <p>Articles found:</p>
  
  <p><a href="https://plumbr.io/blog/memory-leaks/native-memory-leak-example" rel="noreferrer">Article #1</a></p>
  
  <p><a href="https://www.tikalk.com/posts/2017/09/12/2017-09-12-java-native-memory-leak-detection/" rel="noreferrer">Article #2</a></p>
  
  <p><a href="https://gdstechnology.blog.gov.uk/2015/12/11/using-jemalloc-to-get-to-the-bottom-of-a-memory-leak/" rel="noreferrer">Article #3</a></p>
  
  <p><a href="http://www.evanjones.ca/java-native-leak-bug.html" rel="noreferrer">Article #4</a></p>