我注意到在我们的自动化环境中泄漏了大量此类。我试图搜索这个问题,但没有找到任何可用的信息。
ANTS说所有这些实例都是GC根对象。
据我所知,WindowsFormsHost使用HwndSubclass。但是,在此特定方案中,不使用WindowsFormsHost。 ANTS证实了这一点,它不了解WindowsFormsHost的任何实例。
在其他情况下使用HwndSubclass以及如何确保它被正确清理?
编辑: 只是为了确保... Win7(x64)上的环境是WPF4(x86)。
答案 0 :(得分:3)
看起来像是“按设计”。
来自HwndSubclass代码中的评论:
// Allocate a GC handle so that we won't be collected, even if all
// references to us get released. This is because a component outside
// of the managed code (ie. the window we are subclassing) still holds
// a reference to us - just not a reference that the GC recognizes.
然后
// This is LIVE OBJECT because it has a GCHandle. The only time LIVE OBJECTS
// are destroyed is during Shutdown. But Shutdown cleanup is handled through
// the ManagedWndProcTracker and hence no work needs to happen here. PLEASE
// NOTE that reintroducing any cleanup logic in here will conflict with the cleanup
// logic in ManagedWndProcTracker and hence must be avoided. If this instance
// has been disposed its GCHandle is released at the time and hence this object
// is available for GC thereafter. Even in that case since all the cleanup has been
// done during dispose there is no further cleanup required.