Hi,
Im having memory leakage problem. Aspose word is used only for translating document into pdf. This is my code:
try ( ByteArrayOutputStream out = new ByteArrayOutputStream()) {
// Call setLicense method to set license
Document doc = new Document(new ByteArrayInputStream(decodedBody));
doc.save(out, SaveFormat.PDF);
//for testing
return out.toByteArray();
}
Then we use aspse pdf to stamp document and add headers and footers. Headers and footers are added as table and each value is in one cell of the table. Stamping is done with TextStamp class. I am moving document thorught different methods as aspose.pdf.Document object, and i am sure i close it at the end.
Here are the memory logs:
2020-12-01 07:47:21.708 INFO 6413 — [0.0-8443-exec-9] com.simploud.rest.Controller : Memory: max:862, used:293
2020-12-01 07:48:05.828 INFO 6413 — [0.0-8443-exec-7] com.simploud.rest.Controller : Memory: max:862, used:260
2020-12-01 07:48:57.369 INFO 6413 — [0.0-8443-exec-3] com.simploud.rest.Controller : Memory: max:862, used:303
2020-12-01 10:30:35.484 INFO 6413 — [.0-8443-exec-10] com.simploud.rest.Controller : Memory: max:862, used:360
2020-12-01 13:53:09.295 INFO 6413 — [0.0-8443-exec-2] com.simploud.rest.Controller : Memory: max:862, used:384
2020-12-02 09:26:56.757 INFO 6413 — [0.0-8443-exec-8] com.simploud.rest.Controller : Memory: max:862, used:442
2020-12-02 09:46:55.245 INFO 6413 — [0.0-8443-exec-9] com.simploud.rest.Controller : Memory: max:862, used:533
2020-12-02 10:05:43.628 INFO 6413 — [0.0-8443-exec-2] com.simploud.rest.Controller : Memory: max:862, used:267
2020-12-02 10:36:57.917 INFO 6413 — [0.0-8443-exec-4] com.simploud.rest.Controller : Memory: max:862, used:358
2020-12-02 10:37:46.871 INFO 6413 — [0.0-8443-exec-2] com.simploud.rest.Controller : Memory: max:862, used:425
2020-12-02 11:57:34.540 INFO 6413 — [0.0-8443-exec-6] com.simploud.rest.Controller : Memory: max:862, used:277
2020-12-02 11:58:49.171 INFO 6413 — [0.0-8443-exec-5] com.simploud.rest.Controller : Memory: max:862, used:362
2020-12-02 11:59:02.003 INFO 6413 — [0.0-8443-exec-3] com.simploud.rest.Controller : Memory: max:862, used:241
2020-12-02 11:59:46.449 INFO 6413 — [0.0-8443-exec-6] com.simploud.rest.Controller : Memory: max:862, used:342
2020-12-02 11:59:49.159 INFO 6413 — [0.0-8443-exec-5] com.simploud.rest.Controller : Memory: max:862, used:389
2020-12-02 11:59:49.629 INFO 6413 — [0.0-8443-exec-8] com.simploud.rest.Controller : Memory: max:862, used:311
2020-12-02 12:15:34.879 INFO 6413 — [0.0-8443-exec-5] com.simploud.rest.Controller : Memory: max:862, used:406
2020-12-02 12:15:34.905 INFO 6413 — [0.0-8443-exec-6] com.simploud.rest.Controller : Memory: max:862, used:416
2020-12-02 13:50:40.365 INFO 6413 — [0.0-8443-exec-4] com.simploud.rest.Controller : Memory: max:862, used:374
2020-12-02 13:50:55.072 INFO 6413 — [0.0-8443-exec-6] com.simploud.rest.Controller : Memory: max:862, used:446
2020-12-03 06:06:58.774 INFO 6413 — [0.0-8443-exec-9] com.simploud.rest.Controller : Memory: max:862, used:270
2020-12-03 12:12:47.446 INFO 6413 — [0.0-8443-exec-3] com.simploud.rest.Controller : Memory: max:862, used:298
2020-12-03 13:50:40.338 INFO 6413 — [0.0-8443-exec-1] com.simploud.rest.Controller : Memory: max:862, used:414
2020-12-03 13:53:37.554 INFO 6413 — [0.0-8443-exec-2] com.simploud.rest.Controller : Memory: max:862, used:399
2020-12-03 13:53:45.206 INFO 6413 — [0.0-8443-exec-4] com.simploud.rest.Controller : Memory: max:862, used:449
2020-12-03 13:54:04.218 INFO 6413 — [0.0-8443-exec-6] com.simploud.rest.Controller : Memory: max:862, used:344
2020-12-03 13:55:33.190 INFO 6413 — [0.0-8443-exec-5] com.simploud.rest.Controller : Memory: max:862, used:395
2020-12-06 07:52:20.379 INFO 6413 — [.0-8443-exec-26] com.simploud.rest.Controller : Memory: max:862, used:312
2020-12-06 08:04:42.632 INFO 6413 — [io-8080-exec-27] com.simploud.rest.Controller : Memory: max:862, used:326
2020-12-07 08:36:42.619 INFO 6413 — [.0-8443-exec-25] com.simploud.rest.Controller : Memory: max:862, used:424
2020-12-07 08:38:42.495 INFO 6413 — [.0-8443-exec-26] com.simploud.rest.Controller : Memory: max:862, used:315
2020-12-07 08:49:41.870 INFO 6413 — [.0-8443-exec-28] com.simploud.rest.Controller : Memory: max:862, used:405
2020-12-07 08:58:04.405 INFO 6413 — [.0-8443-exec-27] com.simploud.rest.Controller : Memory: max:862, used:386
2020-12-07 09:08:13.066 INFO 6413 — [.0-8443-exec-22] com.simploud.rest.Controller : Memory: max:862, used:412
2020-12-07 09:08:13.220 INFO 6413 — [.0-8443-exec-29] com.simploud.rest.Controller : Memory: max:862, used:463
2020-12-07 09:10:42.883 INFO 6413 — [.0-8443-exec-22] com.simploud.rest.Controller : Memory: max:862, used:349
2020-12-07 09:10:44.800 INFO 6413 — [.0-8443-exec-29] com.simploud.rest.Controller : Memory: max:862, used:550
2020-12-07 09:10:44.997 INFO 6413 — [.0-8443-exec-30] com.simploud.rest.Controller : Memory: max:862, used:393
2020-12-07 09:51:59.319 INFO 6413 — [.0-8443-exec-30] com.simploud.rest.Controller : Memory: max:862, used:482
Here are the logs of memory leak when i stop tomcat:
13-Dec-2020 11:18:56.035 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
2020-12-13 11:18:56.093 INFO 1716 — [ost-startStop-2] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2e12c36: startup date [Sat Dec 12 02:01:18 UTC 2020]; root of context hierarchy
2020-12-13 11:18:56.102 INFO 1716 — [ost-startStop-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
13-Dec-2020 11:18:56.112 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@3b64f005]) and a value of type [com.aspose.pdf.internal.l0k.lb] (value [com.aspose.pdf.internal.l0k.lb@26552390]) 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.
13-Dec-2020 11:18:56.112 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4bcc4138]) and a value of type [com.aspose.pdf.internal.l57u.lc] (value [com.aspose.pdf.internal.l57u.lc@588e5f39]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@447678f5]) and a value of type [com.aspose.pdf.internal.l0f.lI] (value [com.aspose.pdf.internal.l0f.lI@4bb08a48]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@625cc787]) and a value of type [com.aspose.pdf.internal.l57l.l1v] (value [com.aspose.pdf.internal.l57l.l1v@48812b62]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [com.aspose.pdf.internal.l29p.le$1] (value [com.aspose.pdf.internal.l29p.le$1@3f475357]) and a value of type [com.aspose.pdf.internal.l29p.le] (value [com.aspose.pdf.internal.l29p.le@706a6c3d]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@748efd48]) and a value of type [com.aspose.pdf.internal.l4y.l0v] (value [com.aspose.pdf.internal.l4y.l0v@35950280]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@447678f5]) and a value of type [com.aspose.pdf.internal.l0f.lI] (value [com.aspose.pdf.internal.l0f.lI@100260a7]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@625cc787]) and a value of type [com.aspose.pdf.internal.l57l.l1v] (value [com.aspose.pdf.internal.l57l.l1v@d1ee125]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [com.aspose.pdf.internal.l29p.le$1] (value [com.aspose.pdf.internal.l29p.le$1@3f475357]) and a value of type [com.aspose.pdf.internal.l29p.le] (value [com.aspose.pdf.internal.l29p.le@549eeb4a]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@748efd48]) and a value of type [com.aspose.pdf.internal.l4y.l0v] (value [com.aspose.pdf.internal.l4y.l0v@6a9c862c]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@3b64f005]) and a value of type [com.aspose.pdf.internal.l0k.lb] (value [com.aspose.pdf.internal.l0k.lb@6998c480]) 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.
13-Dec-2020 11:18:56.113 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [com.aspose.words.internal.zzQB$1] (value [com.aspose.words.internal.zzQB$1@13f5075f]) and a value of type [com.aspose.words.internal.zzGU] (value [com.aspose.words.internal.zzGU@30926ad0]) 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.
13-Dec-2020 11:18:56.114 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [simploud-app-2.0] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@3e312708]) and a value of type [com.aspose.pdf.internal.l2if.l0if.lI] (value [{f*=com.aspose.pdf.internal.l3if.le@11a2588a, b*=com.aspose.pdf.internal.l3if.lj@2a566a1e, DP=com.aspose.pdf.internal.l2n.lt@931416e, Tc=com.aspose.pdf.internal.l3h.lI@3e8f3e27, Td=com.aspose.pdf.internal.l3v.lI@3dea5774, Tf=com.aspose.pdf.internal.l3h.lj@2475cc4d, Tj=com.aspose.pdf.internal.l3p.lj@274cd39c, Tm=com.aspose.pdf.internal.l3v.lt@6075bf54, EMC=com.aspose.pdf.internal.l2n.lb@f4b05d9, ID=com.aspose.pdf.internal.l2y.lI@556a7d9, Tr=com.aspose.pdf.internal.l3h.lb@444754dc, scn=com.aspose.pdf.internal.l2p.lI@985cc1f, Ts=com.aspose.pdf.internal.l3h.ld@5e37653b, "=com.aspose.pdf.internal.l3p.lt@6e6f794b, MP=com.aspose.pdf.internal.l2n.lj@10f031ee, Tw=com.aspose.pdf.internal.l3h.lu@3732f2db, EI=com.aspose.pdf.internal.l2y.lj@524947bb, Tz=com.aspose.pdf.internal.l3h.lf@4779d998, '=com.aspose.pdf.internal.l3p.lf@5617efd8, B*=com.aspose.pdf.internal.l3if.ld@76936beb, Do=com.aspose.pdf.internal.l3n.lI@6e7f8e1d, ET=com.aspose.pdf.internal.l3t.lf@67433f53, re=com.aspose.pdf.internal.l2f.lt@ec3754c, EX=com.aspose.pdf.internal.l2j.lf@63e29b4c, W*=com.aspose.pdf.internal.l2v.lf@71fffe4b, rg=com.aspose.pdf.internal.l2p.lc@f38ee80, RG=com.aspose.pdf.internal.l2p.ly@1ac4933e, ri=com.aspose.pdf.internal.l2h.lt@6d8b43d1, BDC=com.aspose.pdf.internal.l2n.lf@6308f58d, B=com.aspose.pdf.internal.l3if.lb@2b8c5b82, F=com.aspose.pdf.internal.l3if.lh@156f70ae, G=com.aspose.pdf.internal.l2p.lk@224d2c19, BI=com.aspose.pdf.internal.l2y.lf@6cd0140, J=com.aspose.pdf.internal.l2h.ld@4f540a50, K=com.aspose.pdf.internal.l2p.lt@21d0e914, d0=com.aspose.pdf.internal.l3y.lf@6a3624d3, M=com.aspose.pdf.internal.l2h.lk@41fffd4, d1=com.aspose.pdf.internal.l3y.lI@6bf6738d, sc=com.aspose.pdf.internal.l2p.l: J=com.aspose.pdf.internal.l2h.ld@4f540a50, K=com.aspose.pdf.internal.l2p.lt@21d0e914, d0=com.aspose.pdf.internal.l3y.lf@6a3624d3, M=com.aspose.pdf.internal.l2h.lk@41fffd4, d1=com.aspose.pdf.internal.l3y.lI@6bf6738d, sc=com.aspose.pdf.internal.l2p.lv@4dc8bfae, SC=com.aspose.pdf.internal.l2p.l0if@16831a78, Q=com.aspose.pdf.internal.l2h.lf@6d99a623, BT=com.aspose.pdf.internal.l3t.lI@35abca06, S=com.aspose.pdf.internal.l3if.lk@3d9626d2, sh=com.aspose.pdf.internal.l3l.lI@33c8bbc2, BX=com.aspose.pdf.internal.l2j.lI@1340bb26, T*=com.aspose.pdf.internal.l3v.lj@7850a8b2, W=com.aspose.pdf.internal.l2v.lI@74fcb1dc, BMC=com.aspose.pdf.internal.l2n.lI@21c022a, b=com.aspose.pdf.internal.l3if.lf@141300c4, c=com.aspose.pdf.internal.l2f.lI@69fb2fcc, d=com.aspose.pdf.internal.l2h.lu@7818117e, f=com.aspose.pdf.internal.l3if.lu@1a774105, g=com.aspose.pdf.internal.l2p.lh@16ee77af, h=com.aspose.pdf.internal.l2f.lu@265baff1, i=com.aspose.pdf.internal.l2h.lb@1e70c9a5, cm=com.aspose.pdf.internal.l2h.lI@3eafdc07, j=com.aspose.pdf.internal.l2h.le@5b199772, k=com.aspose.pdf.internal.l2p.lj@20469fc7, gs=com.aspose.pdf.internal.l2h.lv@38e3478b, l=com.aspose.pdf.internal.l2f.lb@786cfb74, m=com.aspose.pdf.internal.l2f.ld@6f59510c, n=com.aspose.pdf.internal.l3if.lt@7bf55387, cs=com.aspose.pdf.internal.l2p.lu@59888c6d, CS=com.aspose.pdf.internal.l2p.le@46206b73, TD=com.aspose.pdf.internal.l3v.lf@63d4838a, q=com.aspose.pdf.internal.l2h.lj@32ec8d1c, s=com.aspose.pdf.internal.l3if.lI@2f1a84c8, v=com.aspose.pdf.internal.l2f.lf@6a2409ab, TJ=com.aspose.pdf.internal.l3p.lb@2d2b1fb6, w=com.aspose.pdf.internal.l2h.lh@7bf9e362, TL=com.aspose.pdf.internal.l3h.lt@3e0411, y=com.aspose.pdf.internal.l2f.lj@4a1d3cec, SCN=com.aspose.pdf.internal.l2p.lf@3f3e4cb6}]) 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.