Утечка памяти в серверных приложениях

Доброе время суток!

Наверное поспешили закрыть тему с Tomcat и многопоточность aspose imaging

Я написал простенький servlet, который в методе doGet исполняет следующий код и больше ничего:

        try (JpegImage image = (JpegImage) Image.load("test_3.jpg"))
        {
            JpegOptions options = image.getJpegOptions();
            options.setCompressionType(JpegCompressionMode.Baseline);
            options.setColorType(JpegCompressionColorMode.YCbCr);
            options.setQuality(90);

            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            image.save(byteArrayOutputStream, options);

            LOG.trace("Size: {}", byteArrayOutputStream.toByteArray().length);
        }
        catch (Exception exception)
        {
        }

Но при остановке сервера выдается сообщения об не освобожденных ThreadLocal.

31-Oct-2025 22:58:53.967 WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [weak-ref-list-remover] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.base/jdk.internal.misc.Unsafe.park(Native Method)
 java.base/java.util.concurrent.locks.LockSupport.park(LockSupport.java:371)
 java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionNode.block(AbstractQueuedSynchronizer.java:519)
 java.base/java.util.concurrent.ForkJoinPool.unmanagedBlock(ForkJoinPool.java:3780)
 java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3725)
 java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1707)
 java.base/java.lang.ref.ReferenceQueue.await(ReferenceQueue.java:67)
 java.base/java.lang.ref.ReferenceQueue.remove0(ReferenceQueue.java:158)
 java.base/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:234)
 com.aspose.imaging.internal.na.t$a.run(Unknown Source)
 java.base/java.lang.Thread.run(Thread.java:1623)
31-Oct-2025 22:58:53.967 WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [DisposerCleaner] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.base/jdk.internal.misc.Unsafe.park(Native Method)
 java.base/java.util.concurrent.locks.LockSupport.park(LockSupport.java:371)
 java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionNode.block(AbstractQueuedSynchronizer.java:519)
 java.base/java.util.concurrent.ForkJoinPool.unmanagedBlock(ForkJoinPool.java:3780)
 java.base/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3725)
 java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1707)
 java.base/java.lang.ref.ReferenceQueue.await(ReferenceQueue.java:67)
 java.base/java.lang.ref.ReferenceQueue.remove0(ReferenceQueue.java:158)
 java.base/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:234)
 com.aspose.imaging.internal.st.a.run(Unknown Source)
 java.base/java.lang.Thread.run(Thread.java:1623)
31-Oct-2025 22:58:53.969 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@13d2a198]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.969 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@65c7d705]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.969 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@314b73f0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.969 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@72ca016e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.969 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@5bd9bb05]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.970 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@6ce9226e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.970 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@77454dbf]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.970 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@48d7aa61]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.970 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@4f453c84]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.971 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@5021c160]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.971 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@2d20aacc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.971 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@69e780ff]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.971 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@32dc7ae3]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.971 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@4b3b044f]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@1642ae82]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@6f5467ac]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@6d07d713]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@2d98b386]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@2ad63b2]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.972 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@657b414b]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.973 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@51f0af4f]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.973 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@5da55e25]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.973 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@7e7d4ff5]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.973 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@325f3a06]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.973 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@14e11cb7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.974 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@7afbb6aa]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.974 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@59e69a43]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.974 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@36d405a8]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.974 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@6fd00647]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.974 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@500d1d9]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.975 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@25cd8307]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.975 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@4ebdabb6]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.975 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@4f185b5d]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.975 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@2009921f]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.975 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@accf78c]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.976 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@36edbb99]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.976 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@40dcfef3]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.976 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@32b911e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.977 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@121e7f7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.977 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@80d9116]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.977 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@4d0e17ed]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.977 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@740f7490]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.978 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d742035]) and a value of type [com.aspose.imaging.system.Threading.Thread] (value [com.aspose.imaging.system.Threading.Thread@785dad71]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.978 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@95e3b93]) and a value of type [com.aspose.imaging.internal.oi.m] (value [com.aspose.imaging.internal.oi.m@11e487ee]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.978 SEVERE [main] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@49b15bf6]) and a value of type [com.aspose.imaging.internal.nq.g] (value [com.aspose.imaging.internal.nq.g@4a822518]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
31-Oct-2025 22:58:53.984 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
31-Oct-2025 22:58:53.988 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
Disconnected from server

Эти ThreadLocal не дают мне покоя :frowning: Я начал исследовать эту проблему.

  1. Чем больше я совершу запросов к servelt, тем больше список.
  2. Я попробовал выполнить много запросов, а сервер остановить через длительный промежуток времени (8 часов), но список ни куда не делся, то есть ThreadLocal так и остался болтаться в памяти.
  3. Я посмотрел код библиотеки (на сколько это возможно при использованной мясорубке) и заметил одну особенность - не происходит вызова remove() над переменными типа ThreadLocal, разве что исключение составляет InterruptMonitor.setThreadLocalInstance(null)

Пожалуйста , поправьте меня если я не прав.

Даже если ключ удаляется (из-за слабой ссылки), значение остаётся привязанным к ThreadLocalMap , пока жив сам поток, а это очень опасно в серверных приложениях, где потоки могут существовать долгое время, полный раскардаш может начаться при использовании пула потоков. Все это содержит в себе Tomcat.

Я допускаю, что могу быть не правым и за ранее прошу прощения, за то что отрываю Вас по пустякам. Но для меня это критично, так как использование Вашего продукта предполагается как библиотека в web-приложении.

@noxius

Hello!

The memory leak issue related to ThreadLocal can indeed be critical for server applications, especially when using a thread pool. You are correct that if a value in ThreadLocal is not removed, it can remain in memory as long as the thread exists, potentially leading to leaks.

Here are some recommendations that may help you address this issue:

  1. Remove values from ThreadLocal: Ensure that you call the remove() method for all ThreadLocal variables when they are no longer needed. This is particularly important in methods that may be called multiple times.

  2. Use try-finally: Wrap the code that uses ThreadLocal in a try-finally block to ensure that remove() is called even in the event of an exception. For example:

    ThreadLocal<MyType> myThreadLocal = new ThreadLocal<>();
    
    try {
        // Your code using myThreadLocal
    } finally {
        myThreadLocal.remove();
    }
    
  3. Monitor threads: Utilize monitoring tools to track active threads and their states. This will help you identify which threads may remain active longer than necessary.

  4. Update the library: Ensure that you are using the latest version of Aspose Imaging, as newer versions may contain fixes for memory leak issues.

If the problem persists, consider reaching out to Aspose support with a detailed description of your situation and your code, so they can assist you more effectively.

I hope this helps you resolve your issue!

Привет @noxius
Ваша тревога вполне понятна. Могу заверить что наша библиотека успешно используется в web сервисах и приложениях, и эти ThreadLocal не создают серьезных проблем.
Но, мы понимаем что желательно от них избавиться вообще.

В следующем году планируется выпуск версии библиотеки без ThreadLocal.
Текущие ThreadLocal содержат очень небольшой набор данных, которые требуют суммарно менее 1Kb даже в случае использовании нескольких потоков (там хранятся 1 экземпляр Integer, 1 экземпляр InterruptMonitor, и 1 экземпляр Locale).
К сожалению сама цель их применения не позволяет из удалять вызовом ThreadLocal.remove(). :frowning_face:

Поэтому нужно время, чтобы найти иной путь для решения тех задач, которые решались с их помощью.
К тому же при использовании одного инстанса библиотеки количество ThreadLocal не увеличивается, а остается неизменным. Если же инстанс останавливается насколько это видно из лога, то они выгружаются вместе с ним, так как привязаны к нему, а не к серверу приложений. Поэтому нет причин сильно переживать по поводу их присутствия.

Задачу по этому вопросу я прикреплю сюда в эту ветку форума.

@noxius
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGJAVA-9111

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Спасибо большое за ответ. Будем следить за обновлениями. Спасибо :slight_smile:

1 Like