Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadCtx.cleanup(): when to call? #94

Closed
rototor opened this issue May 9, 2017 · 4 comments
Closed

ThreadCtx.cleanup(): when to call? #94

rototor opened this issue May 9, 2017 · 4 comments

Comments

@rototor
Copy link
Contributor

rototor commented May 9, 2017

I got a Tomcat warning because the ThreadLocal of ThreadCtx where not destroyed when my webapp unloaded. To silence this warning (and remove the potential memory leak) I call ThreadCtx.cleanup(); in my code after I generated the PDF.

Should PdfBoxRenderer.cleanup() also remove the ThreadLocal? And should we document this somewhere, i.e. that you should call PdfBoxRenderer.cleanup() - at least in a web application?

@rototor
Copy link
Contributor Author

rototor commented May 9, 2017

Maybe PdfBoxRenderer should just be an AutoCloseable, so you can use try-with-resources?

@danfickle
Copy link
Owner

Thanks @rototor
I think some people are still using this with Java 6 so auto close is out. This was definitely an oversight by me. It does say to call cleanup on the documentation for buildPdfRenderer. I think that is the only way that most users will get an instance of a PdfBoxRenderer.

@rototor
Copy link
Contributor Author

rototor commented May 11, 2017

@danfickle AutoCloseable is only available with JDK 1.7+, but Closeable exists since JDK 1.5. If PdfBoxRenderer would extend Closeable and use close() for the cleanup it would be AutoCloseable with JDK 1.7+, because Closeable extends AutoCloseable with JDK 1.7+.

danfickle added a commit that referenced this issue Dec 16, 2017
- Remove deprecated methods.
- Make sure the PDDocument is closed in a finally block.
- Make an explicit method createPDFWithoutClosing for those who need to
post-process.
- Implement Closeable interface so that it can be used with try with
resources.
- Mark unused and untested methods as deprecated.

Thanks @rototor @dtrucken @schmitch
@danfickle
Copy link
Owner

Implemented Closeable as suggested by @rototor. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants