What Strategies and Tools Are Useful for Finding Memory Leaks in .Net

What strategies and tools are useful for finding memory leaks in .NET?

I use Scitech's MemProfiler when I suspect a memory leak.

So far, I have found it to be very reliable and powerful. It has saved my bacon on at least one occasion.

The GC works very well in .NET IMO, but just like any other language or platform, if you write bad code, bad things happen.

Finding memory leaks in C# application

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

  • CLR Profiler
  • .Net Memory Validator
  • GlowCode
  • ANTS Memory Profiler

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.

memory leaks tool for c# .net

You can use the Ants Profiler Pro by Red Gate software

ANTS Performance Profiler is an application profiler for .NET desktop,
ASP.NET, and ASP.NET MVC applications:

  • Find performance bottlenecks fast by profiling both the .NET code and the data access layer
  • Get rich performance data, right-down to line-level timings and expensive database queries
  • Save time going round in circles diagnosing and debugging – let the profiler do the hard work for you
  • Explore unfamiliar code bases

Also check How to identify memory leaks in the common language runtime

Tools for Memory leaks in .Net executable

Redgate has a nice memory profiler you can download here. It even comes with a 14-day trial. I have used it and it is very good.

Can there be memory leaks in .NET? If yes, what are the best tool out there?

You can use a tool like CLR Profiler,VSTS Profiler, .NET Memory Profiler or CLR Profiler to check your object size etc, as they say you can Find Memory Leaks and Optimize Memory Usage in any .NET Program.

Strategies For Tracking Down Memory Leaks When You've Done Everything Wrong

One technique I would try is to systematically reduce the amount of code you need to demonstrate the problem without making the problem go away. This is informally known as "divide and conquer" and is a powerful debugging technique. Once you have a small example that demonstrates the same problem, it will be much easier for you to understand. Perhaps the memory problem will become clearer at that point.

Memory leaks in .NET

Block the finalizer thread. No other objects will be garbage collected until the finalizer thread is unblocked. Thus the amount of memory used will grow and grow.

Further reading: http://dotnetdebug.net/2005/06/22/blocked-finalizer-thread/



Related Topics



Leave a reply



Submit