Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2003

Tip: Looking for answers? Try searching our database.

Memory leak recommendations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Rush - 17 Nov 2003 23:10 GMT
Hello,

We're currently trying to identify the source of a memory leak in a web
application. We notice that the privates bytes increases constantly as the
gc bytes continuously raise and fall at normal intervals (collections), as a
result we feel that this is more than likely a native issue.

The web application as a whole has many assemblies in it and some of these
assemblies do reference and handle unmanaged memory. I was wondering if
anyone had some advice on how to narrow down the culprit assemblies.

I'm currently learning how to use the debugging tools for windows to inspect
this; how to inspect the managed heap and so forth. But if the problem is
unmanaged memory not being cleaned up, how can I discover which assembly is
holding onto the references, or what objects are holding onto the
references? My knowledge of the debugging utilities are unfortunately
limited at this point; something which I am working to fix.

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, etc.)
just this morning :-(

Thanks,
Ben
Sebastien Lambla - 18 Nov 2003 10:26 GMT
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,
when interned i don't know if a string is ever cleaned up completely...

Signature

Sebastien Lambla
http://thetechnologist.is-a-geek.com/blog/

> Hello,
>
[quoted text clipped - 15 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, etc.)
> just this morning :-(
>
> Thanks,
> Ben
Ben Rush - 18 Nov 2003 18:23 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.