?
Solved

C# Memory Leak Detection Tools

Posted on 2002-06-25
15
Medium Priority
?
3,273 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:Michel Sakr
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 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