6

I have created a sample program, with 2 Dialogs. Both Dialogs have a picture box, one calls pictureBox1.Image.Dispose(); in the protected override void Dispose(bool disposing) method and the other doesn't.

When you run the program and use the Task Manager to look at the memory usage, it becomes very obvious that the dialog that does not call pictureBox1.Image.Dispose(); leaks memory really badly.

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

Is there any way to count memory allocation/deallocation for a particular c# source file? At least this was something I was able to do with unmanaged C++.

4

3 Answers 3

10

In VS2010 try the Analyze > Launch Performance Wizard menu option and choose the memory option.

In VS2017 it is Analyze > Performance Profiler...

2
  • I have tried the profiler built into Visual Studio 2010, did not find it particularly helpful unfortunately.
    – user691585
    Apr 4, 2011 at 18:34
  • 1
    Did you turn on the "Also collect .NET object lifetime data" option? May 2, 2011 at 19:24
4

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

There is a 14 day free trial and lots of helpful tutorials to get you started.

3

As alternative to the embedded performance profiler of VS, I find Jetbrains' DotMemory practical and easy.

  • You can see very quickly which objects types, from managed code that are leaking.
  • You got a dashboard with a view on common problems (string duplicates etc)
  • You also have a view on the unmanaged memory. The interface is rather complete, complex (you can really dig and understand many things, and find quickly the culprit objects and code). a view on a snapshot analysis [0] https://www.jetbrains.com/dotmemory/

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.