views:

164

answers:

1

In Windows, what happens to an open HKEY variable if you don't call RegCloseKey before the HKEY goes out of scope? I don't see any errors or warnings, nor any memory leaks when the application closes. MSDN doesn't offer much help, but makes it sound like it somehow uses up resources. Does anyone know what actually happens?

+3  A: 

You orphan a handle, which are a limited (OK, it's a pretty large limit) resource. However, once your app terminates the handle is eventually released by the OS, so the wasted resource is eventually returned to the pool.

It's bad programming practice, though, to allocate something that has limits and not release it when you're done using it.

Ken White
I agree, it is bad practice, but was just wondering what happened, since I didn't see any feedback in Visual Studio.
bsruth