IronPDF 'using' Declaration
IronPDF already disposes of PdfDocument
objects for you without adding a using
declaration. However, if you would like more control over these stored objects, you may use the using
declaration as shown here:
using var pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml);
// some editing functions to the pdf
pdfdoc.SaveAs("output.pdf");
using var pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml);
// some editing functions to the pdf
pdfdoc.SaveAs("output.pdf");
Dim pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml)
' some editing functions to the pdf
pdfdoc.SaveAs("output.pdf")
With the using
declaration, you may choose when to dispose immediately. All code examples work with and without using
statement and it is purely up to your decision whether you would like to use it in this way.
Please note that using the dispose()
method to dispose PdfDocument
objects does not kill Chrome rendering engine. After IronPdf initializes Chrome rendering engine(typically right before the first PDF render), there will be some memory overhead to keep Chrome running. Chrome does not allow its process to be stop and start more than once. Therefore it will keep running in the background, until the process is killed.
Disposing PDF objects will free the memory for those PDF documents (which is usually a small amount), but Chromium Embedded Framework will still be loaded in the background, waiting for your next render.
CEF is automatically shutdown and the memory freed as our internal IronPdf singleton is disposed when the process is killed.
The expected behavior would be that you see a bit of overhead, but subsequent renders should not significantly increase the memory usage over long periods of time.