I learned more about streaming processing, and I created a fairly simple WPF application with the following code (x64 platform build)
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); for (var i = 0; i <= 20000; i++) { Thread thread = new Thread(Test); thread.IsBackground = true; thread.Start(); } } public void Test() { Thread.Sleep(20000); } }
When I run this code, the process takes approximately 560 MB of RAM, while all threads are running / down.

Upon completion of the process, the use of the process is reduced to 125 MB of RAM.
My question is, why is the process using 125 MB of RAM at the moment when the application itself (without the thread example) is using only 30 MB of RAM?
Does it support some of the threads for possible reuse or something else?
EDIT:
Due to some suggestions for improving this code, I would like to point out that I am not asking for its improvement, but to determine the reason for this behavior.
EDIT 2:
This is not thread related, but I tried the case with a large string list in memory, and it did not give the same results. When the list was fully loaded into memory, it took about 1.3 GB of memory, but after the list was set to NULL and GC.Collect() was called, memory usage dropped to 30 MB as expected.
code:
public partial class MainWindow : Window { List<string> stringArray = new List<string>(); public MainWindow() { InitializeComponent(); for (var i = 0; i <= 100000000; i++) {

source share