Release Unmanaged Resources of the Workbook with Node.js via C++
Contents
[
Hide
]
Aspose.Cells provides Workbook.dispose() method to release the unmanaged resources of the Workbook object. The dispose pattern is used only for objects that access unmanaged resources, such as file and pipe handles, registry handles, wait handles, or pointers to blocks of unmanaged memory. This is because the garbage collector is very efficient at reclaiming unused managed objects, but it is unable to reclaim unmanaged objects.
Workbook object now implements the System.IDisposable interface which has a single method Workbook.dispose(). You can either directly call the Workbook.dispose() method or you can use the Using statement to call this method automatically.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Loads the workbook which contains hidden external links
const workbook = new AsposeCells.Workbook(filePath);
// Create workbook object
const wb1 = new AsposeCells.Workbook();
// Call Dispose method
wb1.dispose();
// Call Dispose method via a scoped approach
(async () => {
const wb2 = new AsposeCells.Workbook();
// Any other code goes here
wb2.dispose();
})();