Memory Leaks C# .Net

Viewed 14

Will Memory leaks depends on the machine configuration ?

I have a 32 bit .Net application running in both windows 10 and windows 7. I am not experiencing any memory leaks in windows 10, but there in windows 7.

Any difference, Please give some clarity. Thanks in advance

1 Answers

Memory leaks are more complicated than that.

Essentially, Memory leaks are either forgotten memory that is not collected. Or memory held by our program that isn't being released.

Now it gets more complicated. In .Net applications you have native memory and managed memory and you can leak them both! Unmanaged memory is usually initialized by libraries (Unless you have explicit allocations) so you might focus on managed memory in your case. Managed memories are classes that are holding allocation with references.

So if I have this code, it might "leak":

class MyClass
{
  static int[] MyVariable;

  static MyClass() 
  {
    MyVarialbe = new int[5000000];
  }

}

In .Net GC there's a thing called "Roots" which are the beginning of a reference tree which determines what objects will be collected. After understanding that - You'll need to understand and describe what kind of "memory leak" are you experiencing. My guess is that you see memory goes up from time to time and never released?

.Net application are broad so you'll have to explain what kind of behavior is it doing, what kind of application it is, and what kind of memory leak you see.

There are great tools to inspect it, Profilers by JetBrains, Visual Studio has good profilers as well. If you are able to tune in you can inspect the managed heap and see what takes a lot of memory.


Another key point is to see what OS are you using, you mentioned both Win 7 and Win 10 but you failed to mention their bitness, are they 32 or 64? The Memory Manager (Windows) does couple of different things regarding 32 or 64 and depending on your OS version.

Maybe the memory leak you see are additional libraries that are loaded? For that you have tools like VMMap (Sysinternals) to inspect your virtual memory.

Related