Registry, Close Keys or Not?

  • Thread starter Thread starter Yogi_Bear_79
  • Start date Start date
Y

Yogi_Bear_79

I've been accesing the registry in the two following ways:

using (RegistryKey SubKey = Registry.LocalMachine.OpenSubKey(sSubKey + x))

using (RegistryKey Key = Registry.LocalMachine.CreateSubKey(sSubKey + x))



Should I close the Keys after either or both of these actions? Can you
explain the benifits of either action?
 
Yogi_Bear_79,

Well, one is opening a key, the other is creating it. It all depends on
the action you want to take.

As far as the key is concerned, you are using the using statement, so
any resources associated with the instance will be released when the using
block is exited.

Hope this helps.
 
Back
Top