11,570 questions
Hi TZacks-2728,
- As you said, GC.WaitForPendingFinalizers method is used to suspend the current thread until the thread that is processing the queue of finalizers has emptied that queue.
- If you have code in your finalizers, it's possible that you will need to call GC.Collect() twice, as the first time will cause the finalizers to execute, but the actual memory cannot be cleaned until after the finalizer has completed, which means the subsequent call will catch the object.
Here are some related threads you can refer to.
Will GC.Collect() + GC.WaitForPendingFinalizers() ever NOT reclaim all reclaimable memory?
Is correct to use GC.Collect(); GC.WaitForPendingFinalizers();? - From offical document said, it's possible to force garbage collection by calling Collect. But most of the time, this call should be avoided because it may create performance issues.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.