Reputation: 876
I am noticing large amounts of this class being leaked in our automated environment. I tried to search around for this issue but am not finding any available information.
ANTS says that all these instances are GC root objects.
As far as I understand, HwndSubclass is used by the WindowsFormsHost. However, in this particular scenario WindowsFormsHost is not used. This is confirmed by ANTS, which has no knowledge about any instances of WindowsFormsHost.
In what other circumstances is HwndSubclass used and how can I make sure that it gets cleaned out properly?
EDIT: Just to make sure... the environment is WPF4 (x86) on Win7 (x64).
Upvotes: 2
Views: 1102
Reputation: 876
Looks like it's "by design".
From comments in the HwndSubclass code:
// 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.
and then
// 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.
Upvotes: 3