非托管资源和Dispose() [英] Unmanaged resources and Dispose()

查看:80
本文介绍了非托管资源和Dispose()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一些有关 Dispose()方法的文章,发现应该从 Dispose()方法(或finalize()方法)和非托管资源中显式释放非托管资源.文章说文件句柄和数据库连接对象是非托管资源的示例.谁能解释为什么这些都是不受管理的,如果没有在Dispose()中正确处理,会发生什么?我不知道文件句柄是什么.它们存在于何处?

I was reading some articles about Dispose() method and found that unmanaged resources should be freed explicitly from Dispose() method (or finalize() method) and the article says file handles and database connection objects are examples of unmanaged resources. Can anyone explain why those are unmanaged and what happens if not handled properly in Dispose()? I have no idea about what a file handle is. Where do they exist?

推荐答案

在这种情况下,最容易想到的是这样:

In this context it's perhaps easiest to think of it like this:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆