开发者

SmtpClient.Send causes memory leak

开发者 https://www.devze.com 2022-12-17 13:41 出处:网络
I have a memory leak when calling SmtpClient.Send(). I have a service 开发者_如何学Pythonfor sending emails. I noticed a memory leak in TaskManager. I commented out the SmtpClient.Send() line, and w

I have a memory leak when calling SmtpClient.Send().

I have a service 开发者_如何学Pythonfor sending emails. I noticed a memory leak in TaskManager. I commented out the SmtpClient.Send() line, and when I started the service again, I noticed that the memory usage didn't increase.


It is a very common mistake to assume that Taskmgr.exe is a leak detection tool. The combination of the .NET garbage collector and the Windows heap manager is far too sophisticated to be reverse-engineered from the numbers you see in that tool.

Proof it to yourself by sending thousands of email messages. If SmtpClient.Send() really leaks then your program will quickly crash with a OutOfMemory exception. Get more insight in the memory usage of a .NET program with Perfmon.exe and the performance counters in the .NET CLR Memory category. And a good book, like Richter's CLR via C#.

0

精彩评论

暂无评论...
验证码 换一张
取 消