Solved

C# Memory Leak Detection Tools

Posted on 2002-06-25
15
3,182 Views
Last Modified: 2011-04-14
Hi,

I'm looking for good memory leak detection tools that can analyze c# programs - other than : Purify, Microsoft Application Profiler or .Net memory profiler.

Thanks,
Yishay.
0
Comment
Question by:yl
  • 6
  • 3
  • 2
  • +4
15 Comments
 
LVL 4

Expert Comment

by:kpkp
ID: 7107082
I shouldn't be possible to create memory leaks with managed code in a C# program, it uses a garbage collector for memory management - or am I missing something?
0
 
LVL 1

Author Comment

by:yl
ID: 7107775
Theoretically you are right. However, if a C# program leaves unneeded objects with a reference to them (an application error), than they will not be freed by the garbage collector.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 7112927
>However, if a C# program leaves unneeded objects with a reference to them (an application error), than they will not be freed by the garbage collector.


until the application is terminated or the object gets out of scope..
0
 
LVL 1

Author Comment

by:yl
ID: 7113916
I'm talking on a situation where the application is working for a long time without terminating.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7117439
If its a purely managed application then chances of memory leaks are very slim. There have been instances when InterOp layer can generate some leaks because of Interface pointers not being released by the framework. It has nothing to do with your application. There seems to be some leaks in framework itself. Other than that it does not matter for how long your application runs. GC will kick in when it feels that your system is running low on resources or when its scheduled to run by framework. It runs on non deterministic schedule. You don't have to worry about objects not getting collected. Trust GC.. they will get cleaned up if they are not in use anymore. One thing that you can do to reduce the load and chances of memory leaks are that make sure that you call Dispose on objects that hold refereces to Win32 kernel objects like File handles, GDI objects, etc.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7121502
Any update?
0
 
LVL 1

Author Comment

by:yl
ID: 7122263
I'm not worried about my unreferenced application objects not being collected.
I need the tool in order to find objects that the application forgot to dereference.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 22

Expert Comment

by:CJ_S
ID: 7122568
>> I need the tool in order to find objects that the
>> application forgot to dereference.

That can simply not happen. Eventually (when the GC feels like it or when it is needed) the GC will step in and free your memory.

other than that naveenkohli has a very good reason. Naveen, any reference to that memory leak within the .Net framework?

CJ



0
 
LVL 1

Author Comment

by:yl
ID: 7124027
>> That can simply not happen. Eventually
>> (when the GC feels like it or when it
>> is needed) the GC will step in and free
>> your memory.

I assume you are referring to weak references.

But what about regular refeences? The GC can never free a referenced object (even one that the application forgot to dereference.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7124031
Garbage Collector will know when objects are not being used anymore. It knows it roots and when it goes out of scope. Whenever you have a reference object and you don't use it anymore (and forgot to dereference yourself) the GC will know and remove it when it drops in.

CJ
0
 
LVL 1

Author Comment

by:yl
ID: 7125092
I am talking about objects that are not being used anymore and Belong to some root. They will not be collected by the GC because the application forgot to dereference them and they are still descendants of root objects.
This phenomenon can be common in very large applications (such as ours).

The tool I am looking for will allow to take snapshots of the application and visually present objects that were created between the two snapshots and were not dereferenced.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7125119
yl,
the scenario that you are talking about it more of a programming/implementationproblem rather than framework GC problem. If there is areference to an object anywhere that means that it is in use. GC and JIT compiler is smart in the sense that it can detect any unreachable object. For example if you created a reference to an object and exited that method or function without releasing it, then it becomes orphan. GC can detect that. And in the next cycle it will be cleaned up. You don't have to worry about it. But if you have reference to an object it is still in use, then it will not be cleaned up.

If you are that worried about clean up then you can force GC to run and clean up. But this is a big no no. It will degrade the performance of your application. Just trust GC. If object is not in use and is unreachable by your application, then it wlill go away.

CJ_S,
There is no reference to that memory leak in Interop. But we have seen it happening a lot that COM objects are not being released some time. Which end up in memory leaks.

Naveen
0
 
LVL 1

Author Comment

by:yl
ID: 7127213
naveenkohl,

>> the scenario that you are talking about it more of
>> a programming/implementationproblem rather than
>> framework GC problem

You are right. I am looking for a tool that will allow to detect such problems (other than the following tools: Purify, Microsoft Application Profiler or .Net Memory Profiler).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9385909
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SerCouWisMOD earned 0 total points
ID: 9441761
Question was closed per the recommendation

SerCouWisMOD
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now