Nothing to add for me to this message.
Cor
"William (Bill) Vaughn" <
[email protected]> schreef in
berichtI concur. I've been (lectured) by the dev team that the .NET Garbage
Collector (GC) runs when it feels the need to release more memory--not
at
scheduled or "idle" times. In theory his means on a system with lots of
unused RAM, the GC might not run for hours. In my experience on systems
running performance tests, it's clear that the GC chokes down
performance
on a regular basis, but these systems had limited RAM and lots going on.
There is no truth to the rumor that the GC was designed by members a
garbage handler's union that only collect trash when the streets are
actually blocked.
Several points can be made:
1.. The GC behavior is different than what developers expect based
on
working with VB6. The GC in VB was far more aggressive and constantly
kept
up with released objects.
2.. The GC should not be depended on to release resources held by
objects (like Connections)--we need to do that ourselves in code using
Dispose (which executes Close on a Connection) or simply Close which
releases the resource held by the Connection instance. The memory
allocated to the object is released when the GC runs.
3.. We as developers should be more cognizant of releasing resources
(like Connections and other objects) in code by closing the Connections
and other resources we create.
4.. Calling Dispose does not release memory. It marks the object
instance as "unused" so the GC can release the memory back to the pool.
5.. This GC behavior means that application memory allocations seem
to
grow over time until the GC runs.
6.. We should not try to outthink the GC. Let it do it's job.
However,
we do need to keep its behavior in mind as we code.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
Visitwww.hitchhikerguides.nettogetmore information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
messageTrue.
But its been my experience that the GC does most of its cleanup when
there
is some level of memory pressure, not when "there is nothing elseto
be
done".
Matter of fact I had an application that opened a file, it set the
file
object to nothing (ready for cleanup by the gc) but failed to do a
close or
dispose. But because there was little activity on the machine, lots
of
free
memory, and the application wasn't causing sufficient memory
pressure,
the
gc never cleaned up the "dead" file object that still had the
underlying
file open. There was definitely "nothing else to be done" on the
machine and
within the application process, but the GC did not clean up the
object.
In contrast, on a busy server you will often see the GC run more
often
because of the need to clean resources.
So in my experience it has been the opposite of what Cor has said,
and
from
everything I read you cannot predict when the GC will run, so I was
just
asking Cor for some reference material to back up his statement. Do
know if
what Cor said is true?
"Miha Markic" <miha at rthand com> wrote in message
Cor,
Can you provide a link to documentation where it states that the
GC
does
cleanup when there is nothing else to be done?
GC does cleanup when it decides to do it. It has a built in smart
scheduler that should do in most cases.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:
http://cs.rthand.com/blogs/blog_with_righthand/
Nothing to add for me to this message.