I have an application that creates a lot of threads over time. I noticed that memory usage increases as it starts up and eventually ends up in memory. But the same code is not a memory leak in my colleague environment. We have both versions of .net. I was able to reproduce the problem with the following code example that does not leak on my laptop but on my laptop.
public static void Main(string[] args) { Console.WriteLine("Version " + Environment.Version.ToString()); if (Environment.Is64BitProcess) Console.WriteLine("64"); else Console.WriteLine("32"); while(true) { Thread t = new Thread(() => { Thread.Sleep(1); }); t.IsBackground = true; t.Start(); Thread.Sleep(1); } }
When I run above, it prints the following
Version 4.0.30319.18063 32
In Visual Studio 2012, the target structure for the project is .net framework 4.5. Memory leak project followed by configuration
Project Properties -> Build Platform target: Any CPU Prefer 32-bit: checked
If I uncheck Prefer 32-bit, it does not flow.
Another configuration that has memory leaks,
Project Properties -> Build Platform target: x86 Prefer 32-bit: disabled
The resulting executable that runs on my laptop does not flow on my laptop.
I used the CLR Profiler to search for memory leaks, but it does not show anything that leak. But I see that the working set in the Windows Resource Monitor is increasing by about 1 MB / s.
What causes an increase in memory usage in 32-bit mode in my environment, but not in my colleague?
Csharp_user
source share