This question has already been answered:
Good day.
Here is my code: (I listen to the 25th port of the local machine):
class Program { static void Main(string[] args) { TcpListener SMTP_Listener = new TcpListener(IPAddress.Any, 25); SMTP_Listener.Start(); Console.WriteLine("Starting..."); while (true) { Socket clientSocket = SMTP_Listener.AcceptSocket(); if (clientSocket.Connected) { string _sessionId = clientSocket.GetHashCode().ToString(); Console.WriteLine("Connected: " + _sessionId); new Thread(() => { StartProcessing(clientSocket, _sessionId); Console.WriteLine(">> Client thread is finished: " + _sessionId); }).Start(); } } } static void StartProcessing(Socket clientSocket, string _sessionId) { //ΠΠΈΠΌΠΈΡ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ int _maxMessageSize = 1000000000; //ΡΠ°ΠΉΠΌΠ°ΡΡ Π°ΠΆΠΈΠ΄Π°Π½ΠΈΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ ΠΎΡ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° int _commandIdleTimeOut = 6000000; //Π²ΡΠ΅ΠΌΡ ΠΆΠΈΠ·Π½ΠΈ ΡΠ΅ΡΡΠΈΠΈ int _sessionIdleTimeOut = 80000; int[] arr = new int[1000]; for (int i = 0; i < 1000; i++) { arr[i] = i; } clientSocket.Close(); Console.WriteLine(">> Socket closed for client " + _sessionId); } }
Calling code from another application:
for (int i = 0; i < 30; i++) { try { SmtpClient client = new SmtpClient("machine_name", 25); MailMessage m = new MailMessage("localm@bank.lan", "+380662367263@domen.lan"); m.Body = i.ToString() + " (1)"; client.Send(m); Console.WriteLine(">> " + i + " (1)"); } catch { Console.WriteLine(">> " + i + " (2)"); } }
The question is in performance - when you start the application, it takes 7.156 MB of operative, but after 30 connections, the program starts to occupy 7.548 MB , but after 17 minutes the load has dropped to 7.308 MB and this already remains for.
As I understand it, if the application architecture is correct, then the load should return to the original level, i.e. 7.156 MB of RAM, but this does not happen.
Tell me, please, what could be the reason why the program memory is not released?