正如标题所说。
另外,反过来也是一样的吗?关闭一个RegistryKey会自动释放它吗?
我查看了所有可以找到的文档,但没有任何地方提到这些。
它将在Close()
内部调用Dispose()
方法,这意味着YES
它将被“disposed
”,反之Dispose()
将关闭key
。系统注册表键永远不会closed
。只有正在closed
的keys
- HKEY_PERFORMANCE_DATA
。
Close
方法的.NET源代码:
/**
* Closes this key, flushes it to disk if the contents have been modified.
*/
public void Close() {
Dispose(true);
}
Dispose
方法的.NET源代码:
[System.Security.SecuritySafeCritical] // auto-generated
private void Dispose(bool disposing) {
if (hkey != null) {
if (!IsSystemKey()) {
try {
hkey.Dispose();
}
catch (IOException){
// we don't really care if the handle is invalid at this point
}
finally
{
hkey = null;
}
}
else if (disposing && IsPerfDataKey()) {
SafeRegistryHandle.RegCloseKey(RegistryKey.HKEY_PERFORMANCE_DATA);
}
}
}