I have witnessed a Delphi 6 program that uses FindFirst()
from SysUtils
inside a function. This is a program that runs for months and performs this operation hundreds of times. The surprising thing is that FindClose()
is not called and nothing bad happens.
If I understand that correctly, the program seems to leak file Handles. (In the TSearchRec
record there is a THandle
entry. The whole record is discarded and the THandle
not closed). The thing is that there seems to be no problem. I used process explorer form sysinternal and observed no open file handle to the file found by FindFirst
.
Any explanation?
As described, your program leaks handles. If you call FindFirst
without subsequently calling FindClose
, you leak handles. Do that enough and the program will exhaust the available handle objects and fail.
That you don't see that suggests that you have not yet reached the limit. That you do not observe the leak from Process Explorer suggests that you are not looking at the right information. Or perhaps you have mis-diagnosed the problem completely and either the code that leaks is not called, or the call to FindClose
is made but you have not found it yet.
Rather than spending much more time analysing this, you should fix your code. The bottom line is that unless you match calls to FindFirst
with calls to FindClose
, your program leaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With