Using IronPDF with .NET: A Quick Guide
IronPDF automatically disposes of PdfDocument
objects for you without needing a using
declaration. However, if you would like more control over these stored objects, you may use the using
declaration as shown here:
// Create a PDF document from HTML content and automatically manage resource disposal
using var pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml);
// Perform operations on the PDF document (e.g., editing)
pdfdoc.SaveAs("output.pdf");
// Create a PDF document from HTML content and automatically manage resource disposal
using var pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml);
// Perform operations on the PDF document (e.g., editing)
pdfdoc.SaveAs("output.pdf");
' Create a PDF document from HTML content and automatically manage resource disposal
Dim pdfdoc = Renderer.RenderHtmlAsPdf(ImgHtml)
' Perform operations on the PDF document (e.g., editing)
pdfdoc.SaveAs("output.pdf")
With the using
declaration, you can choose when to dispose of resources immediately. All code examples work with and without the using
statement, and it is purely up to you to decide whether you would like to use it in this way for better resource management.
Please note that using the dispose()
method to dispose of PdfDocument
objects does not terminate the Chrome rendering engine. After IronPdf initializes the 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 stopped and started more than once. Therefore, it will keep running in the background until the process is killed.
Disposing of PDF objects will free the memory for those PDF documents (which is usually a small amount), but the Chromium Embedded Framework (CEF) will still be loaded in the background, ready for your next render.
CEF is automatically shut down, and the memory is freed as our internal IronPdf singleton is disposed of when the process is killed.
The expected behavior is that you see a bit of overhead, but subsequent renders should not significantly increase the memory usage over long periods of time.