释放工作簿的非托管资源
Contents
[
Hide
]
Aspose.Cells 提供 Workbook.Dispose() 方法用于释放 Workbook 对象的非托管资源。Dispose 模式仅用于访问非托管资源的对象,例如文件和管道句柄、注册表句柄、等待句柄或指向非托管内存块的指针。这是因为垃圾收集器在回收未使用的托管对象方面非常高效,但无法回收非托管对象。
Workbook对象现在实现了System.IDisposable接口,该接口有一个方法Dispose()。您可以直接调用Workbook.Dispose()方法,也可以使用Using语句自动调用该方法。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create workbook object | |
Workbook wb1 = new Workbook(); | |
// Call Dispose method | |
wb1.Dispose(); | |
// Call Dispose method via Using statement | |
using (Workbook wb2 = new Workbook()) | |
{ | |
// Any other code goes here | |
} |