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#.
精彩评论