My application (written in C#) was OK in the past several months, but last week suddenly started to cause memory leak. I did not rebuild it, the binaries are the same!
While tried to find out what the root cause would be, I've ended up with the same test application I found later in Thread memory leak. So I simply copied the solution, suggested by Hans, and launched it. The memory leak persisted. Adding GC.Collect() caused only that memory growth became jaggy, as GC recovered a little part of the allocated memory in each call.
Checked with a profiler, all other managed or unmanaged objects were correctly finalized, except something related to threads.
class Program
{
static void test()
{
}
static void Main(string[] args)
{
int cnt = 0;
while (true)
{
Thread test_thread = new Thread(() => test());
test_thread.Start();
if (++cnt % 256 == 0) GC.Collect();
Thread.Sleep(20);
}
}
}
Then I tried the same test code above on another PC, and (surprise!) it was working perfectly, and there was no memory leak at all.
UPDATE: Inspired by this topic .Net Memory Leak when creating lots of threads I tried to build for different target. Using x64 target seems to solve the issue in the test application. Unfortunately my real project contains a 3rd party subproject which cannot be rebuilt.
So it seems, something went wrong on my PC, which prevents GC from working correctly. Could you suggest, what to check, where to look? Thanks in advance.