我想处置的IDisposable的对象(的FileStream ^ FS)的托管C ++(.NET 2.0),并正在错误
I'm trying to Dispose of an IDisposable object(FileStream^ fs) in managed C++ (.Net 2.0) and am getting the error
'Dispose' : is not a member of 'System::IO::FileStream'
它说,我应该调用析构函数来代替。在调用
It says that I should invoke the destructor instead. Will calling
fs->~FileStream();
调用FileStream对象的Dispose方法?为什么我不能调用Dispose?
call the dispose method on the FileStream object? Why can't I call Dispose?
正确的模式是直接删除的对象:
The correct pattern is to just delete the object:
delete fs;
这将被转换成一个调用Dispose()
This will be translated into a call to Dispose()
请参阅此帖子一些的引擎盖下是怎么回事细节。这个成语的好处是,它可以让你写的:
See this post for some of the details of what is going on under the hood. The advantage of this idiom is that it allows you to write:
{
FileStream fs(...)
...
}
和调用了Dispose方法正确......相当于用块在C#。文件流对象仍然分配在托管堆中。
And have the Dispose method called correctly ... equivalent to a using block in C#. The file stream object is still allocated on the managed heap.
上一篇:C#:如何启动一个线程在特定的时间线程、时间、在特定
下一篇:"最大字符串的内容长度配额(8192)时,超过了读取XML数据"错误在发送XML字符串到WCF字符串、配额、长度、错误