Aspose Words - Multiples memory leak warning when application is undeployed on Apache Tomcat 8.5

Hello,

For one of our customer we develop and maintain a Java web application hosted on Apache Tomcat 8.5 which uses Aspose words and cells to generate various type of reports from template.

We recently upgraded Aspose versions:

  • Cells from 8.6 to 21.7
  • Words from 16.11 to 21.7

Since this upgrade there are multiples memory leak warnings related to aspose.words when shutting down Tomcat server. Here below the warnings displayed:

*16-Aug-2021 09:17:35.273 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@353c1101]) and a value of type [com.aspose.words.internal.zzZVp] (value [black [3213]]) 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.*
*16-Aug-2021 09:17:35.274 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@d2a56]) and a value of type [com.aspose.words.internal.zzZVp] (value [null]) 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.*
*16-Aug-2021 09:17:35.275 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@7ab5e5a0]) and a value of type [com.aspose.words.internal.zzZVp] (value [{D36AB133-CE78-47C3-835F-E50691CDA442}]) 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.*
*16-Aug-2021 09:17:35.276 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzXAx$1] (value [com.aspose.words.internal.zzXAx$1@9be2510]) and a value of type [com.aspose.words.internal.zzVXJ] (value [com.aspose.words.internal.zzVXJ@4bac21cc]) 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.*
*16-Aug-2021 09:17:35.277 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@1491c3e5]) and a value of type [com.aspose.words.internal.zzZVp] (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.*
*16-Aug-2021 09:17:35.278 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [***] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@6c7ff2c2]) and a value of type [com.aspose.words.internal.zzZVp] (value [NUMPAGES]) 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.*

Even by commenting out most of the treatment in the source code and by just keeping a simple Word template opening the warnings are displayed.

ByteArrayOutputStream bAOS = new ByteArrayOutputStream();
Document doc = new Document(reportTemplate);
ByteArrayOutputStream docOutStream = new ByteArrayOutputStream();
doc.save(docOutStream, SaveFormat.DOCX);
outputStream.write(docOutStream.toByteArray());

Please note we do not have any similar warnings for Aspose.cells. This is only with Aspose.words.

A similar issue has been already raised in the post here
and the issue is tracked in your system as WORDSJAVA-2480.

Unfortunately we can’t share the WAR package as this is a PRODUCTION one used by our customer.

  • Could you support us for this issue?
  • Any idea how we can debug this issue in Aspose.words?
  • Any news on the fix of the issue WORDSJAVA-2480?

Thanks for your support

@jean.thiry

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please use latest version of Aspose.Words for Java 21.8, create a sample WAR file that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Unfortunately, there is no news available at the moment on this issue.

Hello,

It was not possible for us to share the WAR as it was a production WAR.
However we made a simple WAR and deployed it on Tomcat 8.5.
We got the same Mem Leak warning when Tomcat is shutdown. See here below:

18-Nov-2021 16:02:52.987 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [AsposeWordTest] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@3a27f169]) and a value of type [com.aspose.words.internal.zzZVp] (value [{11855B6C-3B97-4057-BB49-77E2312E3402}]) 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.
18-Nov-2021 16:02:52.987 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [AsposeWordTest] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@67faed37]) and a value of type [com.aspose.words.internal.zzZVp] (value [null]) 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.
18-Nov-2021 16:02:52.987 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [AsposeWordTest] created a ThreadLocal with key of type [com.aspose.words.internal.zzXAx$1] (value [com.aspose.words.internal.zzXAx$1@31d0926c]) and a value of type [com.aspose.words.internal.zzVXJ] (value [com.aspose.words.internal.zzVXJ@1f35234]) 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.
18-Nov-2021 16:02:52.987 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [AsposeWordTest] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@698cfa10]) and a value of type [com.aspose.words.internal.zzZVp] (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.
18-Nov-2021 16:02:52.987 SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [AsposeWordTest] created a ThreadLocal with key of type [com.aspose.words.internal.zzW2D$1] (value [com.aspose.words.internal.zzW2D$1@11840e8b]) and a value of type [com.aspose.words.internal.zzZVp] (value [NUMPAGES]) 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.

The implemented behavior is quite simple : we open the Word template, search for a Bookmark, and set a value in this bookmark.

Here below the code;

InputStream reportTemplate = getClass().getResourceAsStream("/COMPLIANCE_LIST_WORD.updated.rtf");

try {
    Document doc = new Document(reportTemplate);

    BookmarkCollection books = doc.getRange().getBookmarks();

    for (Bookmark book : books) {

        if (book.getName().equalsIgnoreCase("MODEL")) {
            book.setText("MODEL_TEST");
        }
        if (book.getName().equalsIgnoreCase("MSN")) {
            book.setText("MSN_TEST");
        }

    }
    ByteArrayOutputStream bAOS = new ByteArrayOutputStream();
    doc.save(bAOS, SaveFormat.DOCX);

    // Write the output file
    byte[] extractDoc = bAOS.toByteArray();
    FileOutputStream fos = new FileOutputStream("C:\\Temp\\00-test.orig.docx");
    fos.write(extractDoc);
    fos.close();
    LOGGER.info("00-test.orig.docx generated");

} catch (Exception e) {
    // TODO Auto-generated catch block
    LOGGER.error("Error creating doc using updated template");
    e.printStackTrace();
}

COMPLIANCE_LIST_WORD.zip (17.9 KB)

The input Word document is located in the WAR at below location: AsposeWordMemLeakTomcat.war\WEB-INF\classes\COMPLIANCE_LIST_WORD.rtf
I attach the Word doc as well.

I can not attach the WAR. I get an error ‘Sorry, that file is too big (maximum size is 50000kb)’ whereas the file size 30MB.

@JThiry We are working on your request and reply to you soon.

@JThiry You are right, this seems to be the same issue as WORDSJAVA-2480. I have linked you request to it. We will keep you informed and let you know once it is resolved.