question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassLoader memory leak even with minimum configuration

See original GitHub issue

For several weeks I am trying to find out why javamelody leaks ClassLoader even with following minimum configuration! I created a test web app which is empty really; just has two jars (javamelody-core-1.65.0.jar and jrobin-1.5.9.jar) and a minimal web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>LeakTest</display-name>
<filter>
	<filter-name>javamelody</filter-name>
	<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
	<filter-name>javamelody</filter-name>
	<url-pattern>/*</url-pattern>
	<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<listener>
	<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
</web-app>

I really do not have anything else! no class, no xml, no any other jar file. But when I deploy this web app to apache-tomcat-7.0.47 then I Immediately stop the app (even without trying to view it in browser), tomcat says the app has leaks!! this disappears if I run without javamelody-core-1.65.0.jar but with jrobin-1.5.9.jar.

I tried Eclipse Memory Analysis and also YourKit a lot with several configs and settings things to null by reflection but I could not resolve the leak 😠 😢 😫 Please help!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
evernatcommented, May 21, 2017

Because javamelody uses java serialization. And your code is not really necessary (otherwise the Tomcat issue 51195 would have been fixed a long time ago).

1reaction
evernatcommented, May 20, 2017

Using your way, I have seen that there are references to the classloader coming from java.io.ObjectStreamClass$WeakClassKey and $FieldReflectorKey (by using a heap dump in Eclipse MAT, then classloader explorer and path to GC roots). The references are SoftReferences, which by definition are not cleaned by GC but will still be cleaned as needed. So it’s not a real classloader leak, since it will be cleaned as needed.

There is an issue for Tomcat named “Find leaks reports a false positive memory/classloader leak” about that: https://bz.apache.org/bugzilla/show_bug.cgi?id=51195

Read more comments on GitHub >

github_iconTop Results From Across the Web

Classloader-Releated Memory Issues - Dynatrace
It represents a separate memory area, and its size must be configured separately. If this area is full, no more classes can be...
Read more >
ClassLoader & memory leaks: a Java love story - Aloïs Micard
We've been experiencing very strange memory leak in our Java application servers at work: when deploying new version of a micro service, ...
Read more >
How to find classloader leaks with Eclipse Memory Analyser ...
First things first: the heap dump · Find a leaked classloader · Different types of references · Finding the leak · Links to...
Read more >
What is classloader leak? - java - Stack Overflow
A class loader leak occurs if you are creating multiple class loaders over time and expect all classes from older class loaders to...
Read more >
How Do ClassLoader Leaks Happen? - JRebel
From ClassLoaders to Classes ... If you have programmed in Java for some time you know that memory leaks do happen. Usually it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found