SmtpClient.Send causes memory leak

2019-08-21 09:56发布

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

I have a service for 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.

标签: .net smtp
1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-21 10:02

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#.

查看更多
登录 后发表回答