I have used TClientSocket
for many years, including usages in the main thread and in worker thread, and I have never seen TClientSocket
leak any handles.
However, TClientSocket
does default to non-blocking mode, and in that mode it uses AllocateHWnd()
to create a hidden window to receive socket events, and AllocateHWnd()
is not thread-safe. Without seeing your actual code, that is the likely cause of the leaks you are seeing in your worker thread code. The solution to that is simply to not use TClientSocket
is non-blocking mode when used in a worker thread. Use it in blocking mode instead. Which lends itself better to thread-based logic anyway.
However, that does not explain the leaks you are seeing in your main thread code. I doubt TClientSocket
is actually the culprit, and again, without seeing your actual code, it is hard to say for sure.