Hello,
I am trying to make a test to see the amount of memory consumed before and after loading a PDF file using PDFBox, and also the consumed memory after closing the PDF file, but I've noticed that the memory consumed after loading the PDF file is the same after closing the PDF file. It seems that i am doing something wrong, or that the PDF is still loaded in memory! . Here is the code I'm using: private String docPath = "c:\400mb.pdf" public void loadPDFDocument() { printHeap( "1. Heap before Loading PDF Doc:" ); PDDocument document = null; try { document = PDDocument.load(new File(docPath)); printHeap( "2. Heap after loading the PDF Doc:" ); } catch (IOException e) { throw new RuntimeException(e); } finally { if (document != null) { try { document.close(); printHeap( "3. Heap after closing the PDF Doc:" ); } catch (IOException e) { e.printStackTrace(); } } } } public void printHeap( String title ) { long heapSize = Runtime.getRuntime().totalMemory(); long heapFreeSize = Runtime.getRuntime().freeMemory(); System.out.println( title ); System.out.println( "Current heap size: " + heapSize ); System.out.println( "Free heap size: " + heapFreeSize ); System.out.println( "--------------------------------" ); } The output for this code when calling loadPDFDocument() is: 1. Heap before Loading PDF Doc: Current heap size: 265289728 Free heap size: 203194096 -------------------------------- 2. Heap after loading the PDF Doc: Current heap size: 899153920 Free heap size: 343428432 -------------------------------- 3. Heap after closing the PDF Doc: Current heap size: 899153920 Free heap size: 343428432 -------------------------------- Am I doing something wrong here? Best regards, Hesham