SmtpClient.Send causes memory leak

旧城冷巷雨未停 提交于 2020-01-17 03:26:19

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/2115677/smtpclient-send-causes-memory-leak

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!