Hi Richard,
I think when you invoke the first time of garbage collection, some object of
you application still did not get release(its reference count >0), so they
will not
get collect.
Then, in the second time, their reference released, so can be succeeded
collect.
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: "Richard" <ri******@amgen.com>
| Sender: "Richard" <ri******@amgen.com>
| Subject: Need 2 forced garbage collections?????
| Date: Tue, 9 Sep 2003 16:16:47 -0700
| Lines: 39
| Message-ID: <07****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN3KHDYFM6hjJ9CSPS/pDtKXLxUYQ==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183617
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
|
| I'm writing an MS Outlook 2000 Addin in C#. I have
| created C# classes that monitor folder events and do other
| business logic. Things work fine until I want to exit
| Outlook. When I exit Outlook I have to force 2 garbage
| collection cycles in order for all of my folder monitor
| classes to get cleaned up {else Outlook will not unload
| from memory}. In other words my OnDisconnect() method
| looks something like this:
|
| {
| // recursively null out all folder objects
| myOutlookMonitor = null;
|
| Trace.Writeln("First GC.Collect()...");
|
| GC.Collect();
| GC.WaitForPendingFinalizers();
|
| Trace.Writeln("Second GC.Collect()...");
|
| GC.Collect();
| GC.WaitForPendingFinalizers();
| }
|
| I put Trace calls into the destructors for my folder
| monitor classes and indeed I have confirmed that several
| of the destructors do not get called until the second
| GC.Collect() is issued...
|
| Does anybody know why I would need to issue 2 GC.Collect()
| calls? Outlook does succesfully unload from memory after
| I issue the second GC.Collect() and it will NOT unload
| from memory unless I issue 2 GC.Collect() calls....
|
| --Richard
|
|
|