Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current Classes Loaded Constantly Increasing - Memory Leak

I've got a service that has a very slow memory leak. If I analyze the .NET CLR Loading counters, I see that the Current Classes Loaded counter is constantly increasing and matches Total Classes Loaded counter at all times. This gives me the impression that the memory leak is related to resources not being freed (This is just a guess).

The service creates new appDomains each time it performs a task (plug-in architecture).

I need to figure out the class names so I can narrow down the cause of the leak. I'm not very proficient with WinDbg, but I was wondering if anyone could walk me through the steps to enumerate these Loaded classes.

I do have the source code so I can obtain the symbol files if necessary. Thanks in advance for any help!

like image 210
Page Avatar asked Dec 05 '08 14:12

Page


2 Answers

Is this .net 2.0 or higher? If so, you may not be unloading the AppDomain (as Jon Skeet says in the comment).

If it's 1.1 or lower, there is a bug in the AppDomain unload functionality. I.e. it doesn't free up the memory or release resources when an AppDomain is "unloaded".

(This was fixed as of .net 2.0)

like image 180
Andrew Rollings Avatar answered Sep 21 '22 12:09

Andrew Rollings


You can always check what assemblies are loaded in your AppDomain:

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
      Console.WriteLine(assembly.FullName);
}

So if you accidentally load the assemblies in the wrong domain it wont be hard too see.

Edit:

if you want to use WinDgb SOS, here are the supported commands. You're most likely interested in: DumpDomain, DumpClass, DumpAssembly, EEHeap ...

like image 41
Pop Catalin Avatar answered Sep 20 '22 12:09

Pop Catalin