Last week I noticed one of our RO services (which is a Windows service) leaked memory.
More specifically thread handles kept getting created (not threads, just the handles)
After a few months a million handles which then can deplete the entire memory and result in arbitrary applications crashing.
It took me a week to strip down the service and retest before I finally found the cause.
The cause is not (directly) remobjects related but since I lost a huge amount of time I am posting this case so it might help others.
The problem was hard to detect since it does not occur when running as an application (from debugger or normal) but only occurs wehn the application is run as a service.
Furthermore 1 of the 15 machines I tested on does not have the issue.
In the screenshot below you can see the handles (& large working set/private bytes) all related to thread handles.
After some investigation I believe that it must be some finalizer which is blocked because when calling GC.WaitForPendingFinalizers(); the function hangs
By removing code and iteratively deploying the stripped down versions I could see the problem also occurs for services that do virtually nothing (no RO calls are made).
The problem remained until the version where I removed the [STAThread] attribute form my Main function. This attribute was there for historic reasons but has never been an issue (that we noticed) since the application was created in 2019.
So in short: It appears to be important that the main thread uses MTA (multi threaded apartment COM model) instead of STA when running an application as a service.
For the interested people I’ll attach the simplified code which still suffers from the issue