Free Support Forum - aspose.com

File resources problem when converting html - pdf in java- eventual gives 'too many open files'

I’m running some very simple code to convert html to pdf,



com.aspose.pdf.HtmlLoadOptions options = new

com.aspose.pdf.HtmlLoadOptions("/Users/groberts/testclientresults/");



Document d = new Document("/Users/groberts/testclientresults/secure.pdc.html", options);



PdfSaveOptions saveOptions = new PdfSaveOptions();



d.save("/Users/groberts/testclientresults/new.pdf", saveOptions);



d.dispose();



d.close();





It works and does what I want it too, but eventually I get a too many open files error, which leads me to believe that something in your underlying code isn’t releasing files/resources.



On my mac if I do:-

lsof | grep ttf | wc -l

I can see it growing everytime I run the code.

I suspect some font files are being created and held onto.

the loss seems to show a lot of font ttf files.



If there some command I need to call to free up the resources?



lsof:-



java 32702 root 370r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 371r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 372r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 373r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 374r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 375r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 376r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 377r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 378r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 379r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 380r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 32702 root 381r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

Hi Graham,


Thanks for your inquiry. You may use MemoryCleaner class - that clears Aspose.Pdf specific instances. Please use clear() method of MemoryCleaner class at the end of any process as mentioned below. It will improve the memory issue a lot.

…<o:p></o:p>

…<o:p></o:p>

pdfDocument.close();<o:p></o:p>

com.aspose.pdf.MemoryCleaner.clear();

System.gc();



Best Regards,

Thanks, Is that thread safe, as I may have more than one pdfDocument in memory at one time?

Hi Graham,


Aspose.Pdf for Java is thread safe however ensure that a single PDF document is not being accessed my multiple threads.

Hi, It’s still happening I’m afraid…







We’re also doing lots of other conversions xls, ppt, doc and so on…







Are there similar java methods for releasing those font files, I don’t see why it’s holding onto them after I’ve finished with the document?







sudo lsof -i 4 -p 27988 | wc -l



1536





This is within a very short space of time of starting our program…







sudo lsof -i 4 -p 14694 | grep -i font



java 14694 root 7339r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7340r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7341r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7342r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7343r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7344r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7345r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7346r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7347r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7348r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7349r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7350r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7351r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7352r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7353r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7354r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7355r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7356r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7357r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7358r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7359r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7360r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7361r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7362r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7363r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7364r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7365r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7366r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7367r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7368r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7369r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7370r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7371r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7372r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7373r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7374r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7375r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7376r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7377r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7378r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7379r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7380r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7381r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7382r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7383r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7384r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7385r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7386r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7387r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7388r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7389r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7390r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7391r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7392r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7393r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7394r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7395r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7396r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7397r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

java 14694 root 7398r REG 8,3 349232 9928734 /usr/share/fonts/msttcore/arialbd.ttf

Hi Graham,


Thanks for contacting support.

As requested in your other forum thread, please share some details on how we can reproduce this issue in our environment. We are sorry for your inconvenience.

Although non of the above work, we have noticed that in your latest pdf jar release notes, you mention that you’ve fixed the too many open files problem. We’ve tried it and the problem has now gone away, so thanks so much for this, regards
Graham

Hi Graham,


Thanks for your feedback. It is good to know that your issue has been resolved. We have made some other improvements in the latest release as well, so it resolved the issue.

Also please note that in some cases “Open Files Limit” is increased in prodcution systems. Below are some links for setting up open file limits for Red Hat Linux, Ubuntu and MAC, please have a look into these as well if required.

Red Hat:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/chap-Oracle_9i_and_10g_Tuning_Guide-Setting_File_Handles.html
https://community.jivesoftware.com/docs/DOC-37511

Ubuntu:
http://ubuntuforums.org/showthread.php?t=1961208
http://stackoverflow.com/questions/21515463/how-to-increase-maximum-file-open-limit-ulimit-in-ubuntu

Mac:
http://superuser.com/questions/433746/is-there-a-fix-for-the-too-many-open-files-in-system-error-on-os-x-10-7-1


Please feel free to contact us for any further assistance.


Best Regards,