What are the most common (and often overlooked) causes of memory leaks in managed (.net) applications?

后端 未结 11 1141
闹比i
闹比i 2021-02-04 09:32

Please can anyone recommend a quick checklist / best practice guide to help us avoid simple (but subtle) mistakes that cause could cause memory leaks in .net apps

I find

11条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 09:59

    The number one cause of memory leaks in managed applications, in my opinion, is mistakenly believing that you have a memory leak, when in fact you haven't measured properly. Be sure to use a memory profiler to measure exactly what kind of memory leak you have. You may find that you have some other problem.

    But when the leak is real, the major cause would be references to objects keeping those objects live when they're not really needed. Implementing a using statement for almost all objects implementing IDisposable is a good start. The only exception I know of is WCF proxy classes, which should be accessed with a try/catch/finally, and not a using statement.

提交回复
热议问题