When the matching number of RegCloseKey calls was made, the registry was written back to disk and unloaded from memory. (Yes, this means that if a program leaked a registry key, then the registry never got unloaded. Welcome to 16-bit Windows, which trusted software developers not to be stupid.)

https://devblogs.microsoft....20080117-00/?p=23783