destroy
Shuts down the PDF engine and frees all global resources used by the WebAssembly library.
Signature
destroy(): PdfTask<boolean>;
Description
This method is the counterpart to initialize
. It should be called when your application is completely finished with all PDF operations and the engine instance is no longer needed. Calling destroy
ensures that all memory allocated by the PDFium library is released, preventing memory leaks in your application.
After destroy
has been called, the engine instance cannot be used again.
Parameters
This method takes no parameters.
Returns
PdfTask<boolean>
A Task
that resolves with true
once the engine and its resources have been successfully cleaned up.
See Concepts: Tasks for more on how to handle asynchronous operations.
Example
// Assuming 'engine' is an initialized engine instance that is no longer needed
async function cleanupPdfProcessor() {
try {
await engine.destroy().toPromise();
console.log('PDF engine has been shut down and resources are freed.');
} catch (error) {
console.error('Failed to destroy PDF engine:', error);
}
}
// Call this when your component unmounts or your application closes.
cleanupPdfProcessor();
See Also
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.