Using IronPDF with .NET: A Quick Guide

This article was translated from English: Does it need improvement?
Translated
View the article in English

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")
$vbLabelText   $csharpLabel

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.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado