Finding a .NET memory leak?

I created a sample program with two dialogs. Both dialog boxes have a window with an image, one calls pictureBox1.Image.Dispose (); in a secure override, void Dispose (bool disposing) and the other not.

When you run the program and use the Task Manager to look at memory usage, it becomes quite obvious that a dialog that does not call pictureBox1.Image.Dispose (); memory leak is very bad.

Does anyone have a suggestion for a tool that would identify the problem in such a clear way?

Is there a way to calculate the allocation / deallocation of memory for a specific C # source file? At least that was what I was able to do with unmanaged C ++.

+5
source share
3 answers

In VS2010, try the Analyze > Launch Performance Wizard option and select the memory option.

In VS2017, this is Analyze > Performance Profiler...

+10
source

Check out the Ants Profiler: http://www.red-gate.com/products/dotnet-development/ants-memory-profiler/

There is a 14-day free trial and many useful tutorials to get you started.

+4
source

As an alternative to the built-in performance of the VS profiler, I find JetBrains' DotMemory practical and easy.

  • You can very quickly see what types of objects are from the managed code that is flowing.
  • You have a toolbar with a view of common problems (duplicate lines, etc.)
  • You also have a look at unmanaged memory . The interface is quite complete, complex (you can really dig and understand many things, as well as quickly find objects and the code of the offender). a view on a snapshot analysis [0] https://www.jetbrains.com/dotmemory/
0
source

Source: https://habr.com/ru/post/1346603/


All Articles