Re: Memory Cleanup
- From: "Joe" <jbassking@xxxxxxxxxxxxxxx>
- Date: Mon, 23 Oct 2006 10:00:27 -0400
It seems my question is not fully understood. Calling GC.Collect is not the
issue. The issue is that my objects don't get freed.
Take the following:
class A
{
DataTable table;
}
A a = new A();
.... // Do some stuff with class a
a = null;
// Exit method, do other stuff, check memory
// The total memory has not gone down.
When running the profiler is shows that at the time of exit that class A
still had 1 instance alive at end.
Since class A has a DataTable as a member you can image how much resources
this class could take up.
We may at times want to get rid of the original class A and construct
another one so having any of the older class A instances left around isn't
very good.
-Joe
"Göran Andersson" <guffa@xxxxxxxxx> wrote in message
news:%23zX$UhX9GHA.3352@xxxxxxxxxxxxxxxxxxxxxxx
I assume that you previously programmed in an environment having a heap
that uses reference counters and deallocates objects the moment when there
are no more references to it.
The memory management in .NET does not work that way. There are no
reference counters, and nothing happens when objects go out of scope. The
objects just remain in memory waiting for the garbage collector to remove
them.
The garbage collector is only run when needed, which usually happens when
the first generation heap is full. At that time the most of the objects in
the first generation heap are unused, so the garbage collector just moves
the used objects to the second generation, and the first generation is
empty again.
If you force a garbage collection, you will push all the active objects in
the first generation into the second generation, that is why you get a
warning about so many objects being collected in the second generation.
It's normal for a program to accumulate quite some unused objects until
they are collected. That is what makes the memory management efficient.
Joe wrote:
I call GC.Collect() because memory is not freed as quickly as I need it
to be. I already set my objects to null when I'm done with them but if
that object is still referenced somewhere else, setting the original
object to null will not cause it to be freed.
My best guess is that there is still a reference to these objects
somewhere that wasn't set to null and I have no way of find it without
tracing the object through the entire application.
"MMA" <MMA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F3257D24-EAE4-4508-B5D1-868A8C8BAB0A@xxxxxxxxxxxxxxxx
1) Not generally recomended to call GC.Collect programatically, better
to let
runtime determine whens the best time.
2) As part of your trace to see where the memory hog is, you may want to
set
your primative types to null when done, and calling dispose/and setting
to
null all object you are no longer using. Before explicitly calling
dispose.
Best of luck
"Joe" wrote:
I'm trying to track down where objects are referenced because I want to
clean up the memory when I'm done with them. I thought I found all
references but it doesn't seem that way because calling GC.Collect()
doesn't
free very much.
I ran the built-in profiler and I get a warning:
"An abnormal percentage of objects were collected in generation 2,
which is
inefficient. Investigate further by using the Objects Lifetime view."
The top 3 generation 2 are:
System.Decimal
System.Int32
System.Runtime.Serialization.ObjectHolder
I don't think there is anything I could do about Decimal and Int32 but
what
is the ObjectHolder? I do deserialize data but don't know what I can do
to
clean up this object
Thanks,
Joe
.
- Follow-Ups:
- Re: Memory Cleanup
- From: Kevin Yu [MSFT]
- Re: Memory Cleanup
- References:
- Memory Cleanup
- From: Joe
- Re: Memory Cleanup
- From: Joe
- Re: Memory Cleanup
- From: Göran Andersson
- Memory Cleanup
- Prev by Date: Re: Checksum
- Next by Date: Re: Retrieving lead record from CRM 3.0
- Previous by thread: Re: Memory Cleanup
- Next by thread: Re: Memory Cleanup
- Index(es):
Relevant Pages
|
Loading