
Signature
Sebastien Lambla
http://thetechnologist.is-a-geek.com/blog/
Sebastien,
Thanks for the response first off.
The problem is that it appears to be an unmanaged issue; not a managed
issue, so I don't see how inspecting the managed heap with things like the
CLR profiler will help. I guess that's a more refined question I would like
to ask, if a managed executable is requesting unmanaged resources and never
disposing of the them, is it possible to detect this and to detect who the
managed culprit is? The unmanaged blob of memory that was requested by the
process doesn't exist on the managed heap, but the reference to that does
(if requested from a managed resource), can I detect these references and
find out who requested them and never diposed of them?
Thanks again,
Ben
> To be sure as to where the memory leaks come from, you can use the CLR
> Profiler (version2 just came out).
http://www.microsoft.com/downloads/details.aspx?FamilyID=86ce6052-d7f4-4aeb-9b7a
-94635beebdda&DisplayLang=en
> Allocation profiler here:
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=36A3E666-
6877-4C26-B62D-BFD7CB3154AC
> If you interop with COM object, you should take a look at the Debug Probes
> of the CLR Spy tool
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=c7b955c7-
231a-406c-9fa5-ad09ef3bb37f
> The CLR Profiler will give you all the objects allocated and where/why, the
> large object heap, everything you need. Pay attention to string allocations,
[quoted text clipped - 22 lines]
> >
> > My starting point for all of this is
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/DBGc
h02.asp.
> > All of the GC knowledge I have already, but knowledge of using the tools
> > discussed in this article I didn't have until reading it (windbg, sos,
[quoted text clipped - 3 lines]
> > Thanks,
> > Ben
Eric Cadwell - 24 Nov 2003 17:44 GMT
Are you on 1.0?
Be sure that you are calling Dispose on everything that exposes it.
Use these sites as references. Read the scitech PDF closely.
http://www.automatedqa.com/techpapers/net_allocation_profiler.asp
http://www.scitech.se/memprofiler/
http://support.microsoft.com/support/misc/kblookup.asp?id=817723
There are leaks in the framework libraries. You should contact Microsoft
after cleaning up your own code (I had created a few of my own leaks through
event registrations to a static object). They have a hotfix available for
1.0 and 1.1.
HTH;
Eric Cadwell
http://www.origincontrols.com
Kerry Sanders - 25 Nov 2003 00:44 GMT
>Be sure that you are calling Dispose on everything that exposes it.
Is there a list anywhere that gives a rough idea of what objects expose
IDisposable?
Eric Cadwell - 25 Nov 2003 15:33 GMT
In the help index type Dispose method and it will show a list of all classes
that support IDisposable. I'm showing 161 for 1.0 Framework.
For your own classes, if they contain any objects that support IDisposable
make sure that you implement IDisposable.
Call this method from inside the Dispose() method and it will check all the
private instance variables for IDisposable. It saves you from having to
write a bunch of clean up code.
public void Disposer()
{
Type type = this.GetType();
if (type != null)
{
foreach(FieldInfo fi in type.GetFields(BindingFlags.NonPublic |
BindingFlags.Instance))
{
object field = fi.GetValue(this);
if (field is IDisposable)
{
((IDisposable)field).Dispose();
Console.WriteLine("disposed field:" + fi.Name);
}
}
}
}
HTH;
Eric Cadwell
http://www.origincontrols.com
Kerry Sanders - 25 Nov 2003 23:02 GMT
>In the help index type Dispose method and it will show a list of all classes
>that support IDisposable. I'm showing 161 for 1.0 Framework.
Thanks for the response. I found that last night in the MSDN help after
posting. I should have RTFM first. :)
The code tip is cool. I'll make a note of that one.