Willy
A couple of corrections to your post:
|Note that when the GC runs all managed threads are suspended.
This is not true for Concurrent collections. See
http://blogs.msdn.com/clyon/archive/2004/09/08/226981.aspx.
| The GC is activated when a certain managed heap threshold is reached,
A collection can occur if an allocation fails, if memory pressure hits a
certain threshold, if the user induces a collection, and on appdomain
unloads, and various other scenarios.
| this threashold depends on the size of the level 2 cache and is
dynamically
| adjusted according the usage pattern.
As I stated above, the GC uses a variety of criteria to determine when to
collect. Your statement about level 2 cache isn't correct, although the GC
will tune itself based on allocation patterns. Users should not use L2
cache as indication of when the GC will perform a collection.
Hope that helps
-Chris
--------------------
|
|
| | >> Is this a .Net object? If so, if it is holding on to resources, it
should
| >> expose a Dispose method. If it is a COM object, are you calling
| >> Marshal.Release to reduce the reference count once you have finished
with
| > it?
| >
| > Yes, it's a .NET object, but no unfortunately it doesn't expose .Dispose
| > method .
| >
| >> idea, your call to Thread.Sleep isn't needed here. The GC activates on
| >> the
| >> call to GC.Collect and WaitForPendingFinalizers() waits while finalizes
| > are
| >> executed
| > I don't think it's true. GC runs on a separate thread with a priority
| > lower
| > than a main thread. Calling GC.collect() doesn't guarantee that GC will
| > start right away, it's my understanding you're telling runtime to
increase
| > priority of GC, but when it will actually be executed depends on what is
| > currently running and/or scheduled to run, after runtime executes
| > important
| > tasks; then maybe GC.collect() is scheduled to execute or maybe not.
| > Calling
| > GC.Collect() is like kindly suggesting to runtime, maybe you should
start
| > thinking about garbage collection, but when it will do is unknown.
| > Thread.Sleep() will stop current thread and give way to other scheduled
| > task
| > to execute which will hopefully be GC.collect (again it's not 100%, but
| > much
| > better chances)
| > I've seen enough arguments that GC is optimized to do its job when
needed.
| > So I think it makes sense to comment out GC.Collect() , and monitor
memory
| > usage.... I hope it will become more obvious if it's needed or not over
| > time.
| >
|
| The GC runs on a user's thread, not on a separate thread. Note that when
the
| GC runs all managed threads are suspended. The finalizer runs on a
separate
| thread and runs with a higher priority than normal.
| The GC is activated when a certain managed heap threshold is reached,
this
| threashold depends on the size of the level 2 cache and is dynamically
| adjusted according the usage pattern.
| Calling GC.Collect will directly initiate a GC run, it's not like kindly
| suggesting.
|
| Willy,
|
|
|
|