Finding memory leaks in C# application

隐身守侯 提交于 2019-12-01 08:50:17
Oleg Kolosov

You need memory profiler to debug such problems. For example:

Also see suggestions from the other question about memory leaks.

Basically, this boils down to finding the objects in memory that stay here while they shouldn't. It can be event handler holding reference to its class or some collection of objects holding references to their parents, and so on. After finding the root cause you may need to restructure your application to get rid of the unnecessary references. This can be as simple as adding forgotten event unsubscription but in non trivial cases might require applying some structural design patterns. This part is very application specific.

Maybe Process class is the right thing you are searching.
Use Process myProcess = Process.GetCurrentProcess() to get current process.
Then you can use myProcess´s properties like WorkingSet64, PrivateMemorySize64 and so on.

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