I would recommend against early memory/perf optimizations. It's best to
measure where the bottlenecks are and address them, than trying to do early
fixes which may cause other issues. Your GC.Collect loop, for example,
will cause early promotion of objects that would otherwise be considered
garbage. This will result in less memory being freed.
Rico Mariani has a great blog about performance, and talks a lot about the
GC:
http://blogs.msdn.com/ricom
In particular, I recommend:
http://blogs.msdn.com/ricom/archive/...29/271829.aspx http://blogs.msdn.com/ricom/archive/...29/271829.aspx http://channel9.msdn.com/wiki/defaul...Channel9.RicoM
Hope that helps
-Chris
--------------------
|
| > Why do you feel you need to force garbage collections?
| As stated before there is a loop creating new instances of a 3rd party
| object each instances does some processing and outputs data to a report
file
| in PDF format. We tried having to work with one instance in the loop, but
it
| just screws up the formatting of the reports, it's pretty obvious it
needs a
| separate instance per report file.
| As of now this program creates over 100 PDFs, it's possible that
eventually
| there will be much more, perhaps thousands. Performance of this
application
| is not a critical issue, since it's a batch process style app which runs
on
| scheduled basis.
| So, We're Just trying to avoid potential memory problems (out of Memory
| exceptions); we have seen a fair share of those.
|
|
| ""Chris Lyon [MSFT]"" <cl***@online.m icrosoft.com> wrote in message
| news:SY******** ******@TK2MSFTN GXA03.phx.gbl.. .
| > LP,
| >
| > The GC will keep up with object allocations, and collect them when it
| > requires. Like Jay stated, the GC is self-tuning based on your
allocation
| > pattern, so it will find the best time to collect by itself.
| >
| > Why do you feel you need to force garbage collections?
| >
| > -Chris
| >
| > --------------------
| >
| > |
| > | LP,
| > | It does, however you may be hurting the GC's ability to "do a good
job",
| > | rather then helping it.
| > |
| > | For details see Rule #1 at:
| > |
| > | >>
http://blogs.msdn.com/ricom/archive/...29/271829.aspx
| > | >>
http://blogs.msdn.com/ricom/archive/.../02/40780.aspx
| > |
| > | Just remember that "the collector is self-tuning so don't mess with
it"!
| > |
| > | Hope this helps
| > | Jay
| > |
| > | "LP" <lp@a.com> wrote in message
| > | news:Oq******** ******@TK2MSFTN GP09.phx.gbl...
| > | > Hi,
| > | > Considering code below. Will it make GC to actually collect. One
| > | > application
| > | > creates new instances of a class from 3rd party assembly in a loop
(it
| > has
| > | > to). That class doesn't have .Dispose or any similar method. I want
to
| > | > make
| > | > sure GC keeps up with the loop. My reasoning if Thread.Sleep(10 00)
is
| > | > called; GC will take priority it do its work, right?
| > | >
| > | > GC.Collect();
| > | > GC.WaitForPendi ngFinalizers();
| > | > System.Threadin g.Thread.Sleep( 1000);
| > | >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|