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

Free Support Forum - aspose.com

RAM isn't clearing up after pdf processing is completed in RedHat Linux 7.9 which is eventually leading to OS killing the application

Dear Aspose Team,

In our production environment which has RedHat Linux 7.9, RAM doesn’t clear up after pdf processing has completed which leads to RAM clogging and OS OOM-Killer eventually killing the application.

[29719602.298868] Out of memory: Kill process 64504 (java) score 403 or sacrifice child
[29719602.299935] Killed process 64504 (java), UID 1000, total-vm:18134900kB, anon-rss:12381288kB, file-rss:0kB, shmem-rss:0kB

PDFs are being closed in code using Document.close().

We are using Aspose for Java: 21.8

Could you please suggest a remedy for this?

Thanks & Regards,
Madhurendra Narayan Tiwary

@edleads,

Could you please share PDF document(s) and sample code to reproduce the issue. Also, (if possible) kindly try using latest version of the API if it makes any difference. Moreover, it seems you are using Aspose.PDF for Java API, so I am moving your thread to respective forum where you will be assisted accordingly.

Hello Amjad,

This is not related to particular pdf.
The OS (redhat linux 7.9) RAM gets filled up over time and doesn’t go down even when application is idle and eventually OS kills the application.
I think the document that aspose loads is not getting cleared.
Here is the code snipped:

public static byte[] mergePDF(List<String> pdfPhysicalPathList) {
	List<Document> mergedPdfList=new ArrayList<>();
	Document mergedPdfDoc = null;
	for (String pdfPhysicalPath : pdfPhysicalPathList) {
		if (null == mergedPdfDoc) {
			mergedPdfDoc = new Document(pdfPhysicalPath);
			mergedPdfList.add(mergedPdfDoc);
        }
		else{
			Document nextPagesToMerge = new Document(pdfPhysicalPath);
			mergedPdfList.add(nextPagesToMerge);
			mergedPdfDoc.getPages().add(nextPagesToMerge.getPages());
		}
	}

	byte[] mergedDocBytes=null;
	try (ByteArrayOutputStream mergedPdfOutStream = new ByteArrayOutputStream()) {
		int totalNumberOfPages = mergedPdfDoc.getPages().size()
		System.out.println(totalNumberOfPages);
		mergedPdfDoc.save(mergedPdfOutStream);
		mergedDocBytes = mergedPdfOutStream.toByteArray();
        
		return mergedDocBytes;
	} catch (Exception e){}
		finally {
			for(Document mergedPdf:mergedPdfList) {
				pdfDocument.dispose();
				pdfDocument.close();
			}
		}
	}

Regards,
Madhurendra Narayan Tiwary

@edleads

An investigation ticket as PDFJAVA-41790 has been logged in our issue tracking system for the sake of further analysis on this case. We will definitely look into details of it and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.