简体   繁体   中英

Determining Pending Finalizer Sources

I'm coming into a project that has a known issue. The application hangs on a call to GC.WaitForPendingFinalizers . The obvious solution workaround is to remove the WaitForPendingFinalizers call but unfortunately this is being done for us in a third-party assembly, so removal is not an option.

Instead, I want to find the root of the issue and figure out who's finalizer is blocking. The codebase, however, is large and since I'm just coming into it, it's also unfamiliar so I don't even have any gut feelings or intuitions of where it might be. This means I'm going to need to use intrumentation and tools to help find it.

So my questions are:

  1. Will the framework/ee thread that is iterating the Finalizer Queue show up in the Threads view in Studio? The stack trace for this would go a long way to finding where we are hanging.
  2. Is there a tool that will show me pending finalizers and their roots (this is a CF project, but I'm willing to take wide paths to try and find this)?
  3. Anyone have any thoughts or experiences they want to share that might aid in finding this?

This might be one of those cases where Windbg is your friend. Have a look at Tess's blog. Here's an article about debugging a finalizer issue with the !finalizequeue debugger command. http://blogs.msdn.com/b/tess/archive/2007/10/19/net-finalizer-memory-leak-debugging-with-sos-dll-in-visual-studio.aspx

(If you've never done anything with windbg and sos.dll before, do some more reading on Tess's blog. She has some articles that make it very approachable).

I took a quick look in VS (VS 11) and when I break I can see a Thread called "GC Finalizer Thread" and it's caught doing a Sleep() in my destructor.

But your mention of CF may make it an entirely different ballgame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM