Discussion:
When you don't close your key?
(too old to reply)
T
2020-01-06 00:59:44 UTC
Permalink
Hi All,

https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey

Just out of curiosity, if you don't close your key, for
whatever reason, what happens?

Many thanks,
-T
Apd
2020-01-06 02:06:21 UTC
Permalink
Post by T
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
The handle to the registry key will still be available for your
program's use. It will be closed on program exit. If you kept opening
keys without closing returned handles, say in a loop, you'd eventually
run out and get an error. I expect there's a limit before the max
value of a 32 bit integer is exceeded.
T
2020-01-06 04:43:09 UTC
Permalink
Post by Apd
Post by T
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
The handle to the registry key will still be available for your
program's use. It will be closed on program exit. If you kept opening
keys without closing returned handles, say in a loop, you'd eventually
run out and get an error. I expect there's a limit before the max
value of a 32 bit integer is exceeded.
Thank you!


I was hoping it would close on program exist and not turn into
a memory leak
Charlie Gibbs
2020-01-06 04:47:14 UTC
Permalink
Post by T
Post by Apd
Post by T
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
The handle to the registry key will still be available for your
program's use. It will be closed on program exit. If you kept opening
keys without closing returned handles, say in a loop, you'd eventually
run out and get an error. I expect there's a limit before the max
value of a 32 bit integer is exceeded.
Thank you!
I was hoping it would close on program exist and not turn into
a memory leak
Probably. But not releasing resources as soon as you're finished
with them is a bad habit to get into.
--
/~\ Charlie Gibbs | Microsoft is a dictatorship.
\ / <***@kltpzyxm.invalid> | Apple is a cult.
X I'm really at ac.dekanfrus | Linux is anarchy.
/ \ if you read it the right way. | Pick your poison.
T
2020-01-06 04:54:45 UTC
Permalink
Post by Charlie Gibbs
Post by T
Post by Apd
Post by T
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
The handle to the registry key will still be available for your
program's use. It will be closed on program exit. If you kept opening
keys without closing returned handles, say in a loop, you'd eventually
run out and get an error. I expect there's a limit before the max
value of a 32 bit integer is exceeded.
Thank you!
I was hoping it would close on program exist and not turn into
a memory leak
Probably. But not releasing resources as soon as you're finished
with them is a bad habit to get into.
*.tmp file run amok

:'(
JJ
2020-01-06 16:16:58 UTC
Permalink
Post by T
Hi All,
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
Many thanks,
-T
Application memory leak.
T
2020-01-06 20:10:23 UTC
Permalink
Post by JJ
Post by T
Hi All,
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
Just out of curiosity, if you don't close your key, for
whatever reason, what happens?
Many thanks,
-T
Application memory leak.
I thought the handle automatically closed when your
program closed?
R.Wieser
2020-01-07 09:04:39 UTC
Permalink
T,
I thought the handle automatically closed when your program closed?
When you step into a car and it drives off the doors automatically close
themselves for some reason. Still, most people close doors before that.
Why ?

In other words: Even if it all the handles are automatically closed when a
program terminates (which I'm not too sure about - there are too many types
of handles) its a good idea to clean up after yourself.

Just imagine you opening a file for exclusive access (rewriting parts of its
contents perhaps) and not closing the handle. Noone can than access that
file until your program terminates and auto-closes that handle ...

Alos imagine that you have a handle that /doesn't/ get auto-closed ...
Yep, you could be looking at an OS that crashes/freezes because of either
running outof handles, memory, or simply because it cannot access something
it needs. :-(

Regards,
Rudy Wieser
T
2020-01-07 14:32:57 UTC
Permalink
Post by R.Wieser
T,
I thought the handle automatically closed when your program closed?
When you step into a car and it drives off the doors automatically close
themselves for some reason. Still, most people close doors before that.
Why ?
In other words: Even if it all the handles are automatically closed when a
program terminates (which I'm not too sure about - there are too many types
of handles) its a good idea to clean up after yourself.
Just imagine you opening a file for exclusive access (rewriting parts of its
contents perhaps) and not closing the handle. Noone can than access that
file until your program terminates and auto-closes that handle ...
Alos imagine that you have a handle that /doesn't/ get auto-closed ...
Yep, you could be looking at an OS that crashes/freezes because of either
running outof handles, memory, or simply because it cannot access something
it needs. :-(
Regards,
Rudy Wieser
Hi Rudy,

I assiduously run close when I am done. I was just
curious what happened.

-T
R.Wieser
2020-01-07 14:43:01 UTC
Permalink
T,
Post by T
I assiduously run close when I am done.
Thats good.
Post by T
I was just curious what happened.
I hope that what I described gave you at least an idea of what could happen.

Regards,
Rudy Wieser
T
2020-01-07 15:22:40 UTC
Permalink
Post by R.Wieser
T,
Post by T
I assiduously run close when I am done.
Thats good.
Post by T
I was just curious what happened.
I hope that what I described gave you at least an idea of what could happen.
Regards,
Rudy Wieser
Hi Rudy,

I have been scouring example on the web. Most
confuse the dickens out of me. Your examples
and wonderfully clear. They have saved me
hours. I love them!

-T
JJ
2020-01-07 22:03:13 UTC
Permalink
Post by T
Post by JJ
Application memory leak.
I thought the handle automatically closed when your
program closed?
_Application_ memory leak. Not system memory leak.

Meaning that, if the application memory leak is not fixed, the application
would keep allocating memory, and/or system resources for _that_ application
instance. Kind of like the Firefox web browser, where we need to restart it
after relatively long usage, because its memory usage just keep getting
larger and larger even though we already closed all tabs.

Loading...