bsruth
bsruth

Reputation: 5502

What happens if I don't call RegCloseKey on an opened key?

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?

Upvotes: 5

Views: 845

Answers (1)

Ken White
Ken White

Reputation: 125669

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.

Upvotes: 6

Related Questions