> -----Ursprüngliche Nachricht----- > Von: Mark Thomas <ma...@apache.org> > Gesendet: Donnerstag, 24. März 2022 09:32 > An: users@tomcat.apache.org > Betreff: Re: Question to possible memory leak by Threadlocal variable > > On 24/03/2022 07:57, Thomas Hoffmann (Speed4Trade GmbH) wrote: > > <snip/> > > > Is it correct, that every spawned thread must call tl.remove() to cleanup > > all > the references to prevent the logged warning (and not only the main > thread)? > > Yes. Or the threads need to exit. > > > Second question is: How might it cause a memory leak? > > The threads are terminated and hold a reference to this static variable. But > on the other side, that class A is also eligible for garbage collection after > undeployment. > > So both, the thread class and the class A are ready to get garbage > > collected. Maybe I missed something (?) > > It sounds as if the clean-up is happening too late. Tomcat expects clean-up to > be completed once contextDestroyed() has returned for all > ServLetContextListeners. If the clean-up is happening asynchronously (e.g. > the call is made to stop the threads but doesn't wait until the threads have > stopped) you could see this message. > > In this case it sounds as if you aren't going to get a memory leak but Tomcat > can't tell that at the point it checks. > > Mark > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org
Hello Mark, thanks for the information. The shutdown of the framework is currently placed within the destroy() method of a servlet (with load on startup). At least the debugger shows that servlet-->destroy() is executed before the method checkThreadLocalMapForLeaks() runs. I will take a look, whether the threads already exited. Thanks! Thomas