Nick,
I have been using the .Net Memory Profiler pretty heavily for quite some
time. At first, it can be a little confusing, but I have not found another
tool that gives you the information as usefully as this profiler. The CLR
Profiler is good, but if your app is of a decent size, you can sit there all
day watching it draw pretty pictures.
What the .Net Memory Profiler provides which I find most useful is the list
of root paths to an object. As far as I can see, the CLR Profiler and all
other memory profilers I've tried just show you all references, which is a
lot when you are looking at windows forms (event handlers are everywhere).
The root paths are the reasons why the object isn't collectible, and hence
the root paths are the only information you need to find a memory leak.
So. The way you are using the profiler sounds correct to me. Take a
snapshot, let it do some work and get to a stage where you think its memory
should be freed, and take another snapshot. Go View->Class Filter->Show
Classes With New Or Removed Instances. This will basically show you what was
created or collected between the two snapshots.
You can then look through the list of classes and find objects that you
think should have been created and then collected, but the profiler shows as
still alive. Double click on the suspicious classes to go to the list of
instances. You can have a toy with the allocation stacks to find which
instances you're interested in, then pick one and double click it to see its
details. The list of root paths that show are the reasons why the object has
not been collected. From this, you can trace it back to the the source of
the problem and change your code to free up the appropriate references.
Be aware that the profiler does a full GC when taking a snapshot. Hope this
helps!
Niall
[quoted text, click to view] "Nick Carter" <nickcarter@goawayspam.com> wrote in message
news:usjEk3z5DHA.2748@TK2MSFTNGP09.phx.gbl...
> Vadym,
>
> > Memory will never be released if you have strong references to the
> objects.
>
> The references to objects are released (because the references go out of
> scope) so the objects are released.
>
> > ensure that objects that use unmanaged
> > resources have implemented Dispose method.
>
> Fortunately we have no objects which use unmanaged resources (except for
the
> classes in the .NET Framework which uses unmanaged resources).
>
> > Try to use CLR Profiler from Microsoft, it will show you the heap map &
> the
> > amount of memory objects of particular type consume....
>
> Thanks. I started to look at it but it was a bit daunting. I will take
> another look.
> Nick
>
> "Vadym Stetsyak" <pdsdev@ukr.net> wrote in message
> news:e2vGqoz5DHA.2736@TK2MSFTNGP09.phx.gbl...
> > Memory will never be released if you have strong references to the
> objects.
> > Try to use weak references, or ensure that objects that use unmanaged
> > resources have implemented Dispose method.
> >
> > Try to use CLR Profiler from Microsoft, it will show you the heap map &
> the
> > amount of memory objects of particular type consume....
> >
> > "Nick Carter" <nickcarter@goawayspam.com> wrote in message
> > news:eoNewgz5DHA.1948@TK2MSFTNGP12.phx.gbl...
> > > I am searching for a suspected memory leak and I have made some
> > assumptions
> > > and I would be
> > > grateful if someone could check my thinking...
> > >
> > > I have a remoting server that I believe has a memory problem. My first
> > > assumption is that I
> > > believe it has a memory problem because I am checking "Mem Usage" in
> Task
> > > Manager. One
> > > morning the Mem Usage is, say, 100Mb and the next morning it is, say,
> > 200Mb
> > > (after a
> > > complete enforced garbage collection) and the next morning it is
higher
> > yet
> > > again.
> > > Eventually the remoting server throws an out of memory exception. So
my
> > > first assumption is
> > > that it is safe to use the Mem Usage figure in this way. I know I
could
> > use
> > > .NET's memory
> > > performance counters instead but Task Manager was certainly present on
> the
> > > target machine
> > > so it was quick and easy.
> > >
> > > My second assumption is that the increase in memory is a consequence
of
> a
> > > memory leak. I
> > > wonder if this is actually true. I am wondering if the garbage
collector
> > is
> > > resizing
> > > generation 0, 1 and 2 so that they are bigger so that they can more
> easily
> > > cope with the
> > > load that it is under. If this were the case then surely the increase
in
> > > memory requirement
> > > is simply normal behaviour and not a sign of a memory leak.
> > >
> > > I am using SciTech's .NET Memory Profiler to see if there is a memory
> > leak.
> > > I am new to this
> > > tool so I could be using it wrong. I take a snapshot once the remoting
> > > server is up and
> > > running and has been doing a little bit of normal processing. Then
when
> I
> > > think the memory
> > > requirement has gone up unnecessarily and is not coming down again
(even
> > > after a garbage
> > > collection) I take another snapshot and compare them. My next
assumption
> > is
> > > that if the
> > > "Delta" column shows "0" differences for all classes between the two
> > > snapshots then there is
> > > no memory leak. Is this right ?
> > >
> > > I am also wondering if the memory leak could be in unmanaged code
> instead
> > of
> > > managed code. I
> > > am not familiar with how unmanaged code handles memory and if I would
> see
> > a
> > > memory leak that
> > > originated from unmanaged code.
> > >
> > > Any pointers on any of these issues would be gratefully received.
> > >
> > > Thanks.
> > >
> > > Nick Carter
> > >
> > >
> >
> >
>
>