7

On tomcat/manager when I click on find leaks button I get the following message:

The following web applications were stopped (reloaded, undeployed), but their classes from previous runs are still loaded in memory, thus causing a memory leak (use a profiler to confirm):

This is actually causing big problems for me because when I need to re-deploy an app with some changes, the old version remains in the server and when I try to use it I get:

IllegalStateException: Illegal access: this web application instance has been stopped already

Even though in tomcat/manager the application shows as started.

How do I resolve this? I looked at here but did not solve the problem. I tried running jps command to get pid of JVM but it doesn't return the JVMs, I guess due to permissoin issue.

Is it possible to configure tomcat somehow so that when an application is undeployed, it shouldn't keep any classes of that application in the memory?

The question How to purge tomcat's cache when deploying a new .war file? Is there a config setting? is not solving my problem as I followed the steps given there:

  • undeploy the app
  • stop tomcat
  • delete the app from `work` directory of tomcat
  • clear browser cache
  • start tomcat
  • put the war file in `webapps`
  • wait a few moments
  • start the app

those steps didn't solve the problem

sticky_elbows
  • 1,344
  • 1
  • 16
  • 30
  • Possible duplicate of [How to purge tomcat's cache when deploying a new .war file? Is there a config setting?](https://stackoverflow.com/questions/7974882/how-to-purge-tomcats-cache-when-deploying-a-new-war-file-is-there-a-config-se) – Casper Sep 12 '18 at 12:23
  • 1
    similar @Casper, but the given answers dont actually solve my problem – sticky_elbows Sep 12 '18 at 12:33
  • Can you update your question with an answer to this question: did you turn tomcat off and on again? – Casper Sep 12 '18 at 12:36
  • ok just did @casper. so, do you know a way to configure tomcat so that the classes from previous runs don't remain in memory?? – sticky_elbows Sep 12 '18 at 12:44
  • What about the answer on this question? https://stackoverflow.com/questions/14873219/cannot-undeploy-a-web-app-completely-in-tomcat-7 – Casper Sep 12 '18 at 13:00
  • still not @casper, is to prevent any files being locked so that you are able to delete them. This doesn't mean some classes won't remain in tomcat's memory – sticky_elbows Sep 12 '18 at 13:33
  • What do you mean by "classes from previous runs don't remain in memory"? If you stopped and started Tomcat nothing from the previous run will "remain in memory". – Dave Newton Sep 12 '18 at 13:35
  • 1
    @DaveNewton do you know a way to configure tomcat to avoid keeping classes in memory from previous run when you re-deploy an application? – sticky_elbows Sep 12 '18 at 13:44
  • @sticky_elbows did you find a working solution to this annoying problem? – smoothBlue Sep 03 '20 at 08:08

1 Answers1

0

There is no way to configure tomcat to drop classes that are still referenced. An easy way (probably not the only one) to cause this is to start a thread from your webapplication and not terminate it when the app is undeployed: To tomcat, this thread is then unavailable, but for the JVM, the running thread is a valid root for classes that can't be garbage collected.

Tomcat does its best to detect and indicate such a condition, but really can't go against the JVM and garbage collector and discard perfectly valid objects that are still referenced.

The steps you give, including stopping and starting tomcat, seem impossible: Once you terminate the JVM, the only chance for a newly started JVM to reference the old classes is if it gets hold of them. But you also state that you're deleting the work directory (what about the temp directory?). You should also make sure that you're actually deleting the right content, not some other server's content in a similar directory. Other than that: It seems you're just missing an almost obvious place where the old classes are located. Once they're picked up on restart, the condition that I'm describing above might kick in. There's no way around implementing the webapp to behave nicely and not start random background threads without terminating them.

You might want to check if CATALINA_HOME and CATALINA_BASE are different and might give a hint about other applications deployed under the same name, and if your application gets started when you just delete the files you describe, then start (without new deployment)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90