We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose PDF/Word JAVA possible memory leak?

I am licensed to use Aspose total for JAVA and am currently using Aspose.PDF v22.8 and Aspose.Words v22.8 running on Tomcat 8.5.72 using JDK 1.8.0_301.

When shutting down tomcat, i notice the messages below. Is this an indication that there is a memory leak within Aspose/PDF and Aspose/Words. If so, how do i fix it? For PDF, I am running Document.close() after every use and MemoryCleaner.clear upon shutdown. For Words, there is no command to close the document after using it so i assume it automatically shuts down.


SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@54dc0d5e]) and a value of type [com.aspose.pdf.internal.l159if.lc] (value [com.aspose.pdf.internal.l159if.lc@445e9b15]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4d5b4fb]) and a value of type [com.aspose.pdf.internal.l10n.lf[]] (value [[Lcom.aspose.pdf.internal.l10n.lf;@3af516b7]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@e774a4a]) and a value of type [com.aspose.pdf.internal.l149t.l0u] (value [com.aspose.pdf.internal.l149t.l0u@3e41eea2]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@5c80b17]) and a value of type [com.aspose.pdf.internal.l158h.l1v] (value [com.aspose.pdf.internal.l158h.l1v@31d924fe]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@dcf899]) and a value of type [com.aspose.pdf.internal.l6v.l0v] (value [com.aspose.pdf.internal.l6v.l0v@40b9d260]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [com.aspose.words.internal.zzY4G$1] (value [com.aspose.words.internal.zzY4G$1@1a15e440]) and a value of type [com.aspose.words.internal.zzZ1z] (value [com.aspose.words.internal.zzZ1z@14311fb0]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [com.aspose.pdf.internal.l31h.le$1] (value [com.aspose.pdf.internal.l31h.le$1@76f1ce94]) and a value of type [com.aspose.pdf.internal.l31h.le] (value [com.aspose.pdf.internal.l31h.le@5daa53ed]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [com.aspose.words.internal.zzdW$1] (value [com.aspose.words.internal.zzdW$1@68288bfc]) and a value of type [com.aspose.words.internal.zzYHA] (value [HYPERLINK]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7478c5d6]) and a value of type [com.aspose.pdf.internal.l2u.lb] (value [com.aspose.pdf.internal.l2u.lb@c0520a3]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [com.aspose.words.internal.zzdW$1] (value [com.aspose.words.internal.zzdW$1@2fe43305]) and a value of type [com.aspose.words.internal.zzYHA] (value []) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1d00155a]) and a value of type [com.aspose.pdf.internal.l10n.lb] (value [com.aspose.pdf.internal.l10n.lb@38a53e61]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@421f6e17]) and a value of type [com.aspose.pdf.internal.l127k.lb] (value [com.aspose.pdf.internal.l127k.lb@4c6d014a]) 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.
Oct 12, 2022 7:24:22 AM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [Phoenix2] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@5c80b17]) and a value of type [com.aspose.pdf.internal.l158h.l1v] (value [com.aspose.pdf.internal.l158h.l1v@79cbbce6]) 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.

@bgonzalez,

Seems like a native Tomcat issue, especially on Windows. Some files may be locked when you undeploy a web application. You can see a similar issue here: https://stackoverflow.com/questions/12948982/how-to-delete-loaded-jar-files-in-tomcat.

So, to prevent such problems, please try inserting the following line into your …\conf\context.xml file:

<Context antiResourceLocking="true">

In case this does not help, please provide the following information:

  • OS version you are using;
  • the version of Tomcat you are using;
  • simple java application without compilation errors so we can reproduce the problem on our side.

That did not help.

I am running on the following:
OS: Windows 10 Enterprise v21H2
OS build: 19044.2006
Tomcat: v8.5.72
JDK: v1.8.0_301

I noticed that this error on shutdown occurs when i convert word to pdf and the error messages multiplies depending on how many time i run the word to pdf conversion.

The code to run the word to PDF conversion is as follows:

com.aspose.words.License wordLicense = new com.aspose.words.License();
wordLicense.setLicense(DocumentHelper.class.getResourceAsStream("Aspose.Total.Java.lic"));
com.aspose.words.Document worddoc = new com.aspose.words.Document(inputFileName);
worddoc.save(outputFileName,SaveFormat.PDF);

Maybe it is wrong to set the license every time the code is executed. should i move the license setup upon application startup?

@bgonzalez,

yes, please, try to move the license setting on application startup instead of every time you do the conversion and use the advice above by changing the \conf\context.xml file.

I moved the license initialization to startup and still the same thing. I think the culprit is the aspose word convert to PDF code below. Is there anyway to programmatically close the word document to ensure that it is garbage collected, just like the pdf.Document.close() command?

com.aspose.words.Document worddoc = new com.aspose.words.Document(inputFileName);
worddoc.save(outputFileName,SaveFormat.PDF);

@bgonzalez,

If you pass a file name, then the Document class opens and closes the file automatically. The Document class opens the file in the constructor, loads it fully into memory and closes it. Also, the Document class creates a file when you call Save and then closes it when Save returns.

This issue has been logged as WORDSJAVA-2712 . We will keep you posted and will let you know as soon as the issue is resolved. Please accept our apologies for the inconvenience.