2012-02-13 2 views
1

자동 환경에서이 클래스가 대량 유출 된 것을 알고 있습니다. 이 문제를 해결하기 위해 노력했지만 가능한 정보를 찾지 못했습니다.MS.Win32.HwndSubclass의 메모리 누수

ANTS는이 모든 인스턴스가 GC 루트 개체라고 말합니다.

내가 이해하는 한, HwndSubclass는 WindowsFormsHost에서 사용됩니다. 그러나이 특정 시나리오에서는 WindowsFormsHost가 사용되지 않습니다. 이는 WindowsFormsHost의 인스턴스에 대해 알지 못하는 ANTS에 의해 확인됩니다.

다른 상황에서는 HwndSubclass가 사용되며 어떻게 제대로 정리할 수 있습니까?

EDIT : Win7 (x64)의 환경은 WPF4 (x86)입니다.

답변

2

"디자인 상"인 것처럼 보입니다. 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.