2010-09-02 71 views
1

我有一個Silverlight 3應用程序,它似乎在泄漏DispatcherTimer對象。至少,隨着時間的推移,當應用程序運行時,我覺得更多的人在堆上:如何在windbg中找到DispatcherTimer的事件處理程序

dumpheap型DispatcherTimer

返回他們的increating數!

我想找到這些Tick事件處理程序方法,以便我可以確定它們在我的代碼中創建的位置。

當我嘗試在WinDbg中傾倒的其中之一,我得到的是這樣的:

!do 098b9980 
Name:  System.Windows.Threading.DispatcherTimer 
MethodTable: 0bfd4ba0 
EEClass:  0bc98d18 
Size:  20(0x14) bytes 
File:  C:\Program Files (x86)\Microsoft Silverlight\4.0.50524.0\System.Windows.dll 
Fields: 
     MT Field Offset     Type VT  Attr Value Name 
0bfd1538 40008be  4 ...eObjectSafeHandle 0 instance 098b9994 m_nativePtr 
0bfd3d0c 40008bf  8 ...reTypeEventHelper 0 instance 098b99ac _coreTypeEventHelper 
506a07e4 40008c0  c  System.Boolean 1 instance  1 _isEnabled 
0bfd3c68 40008c1  cec ...ependencyProperty 0 shared static IntervalProperty 
    >> Domain:Value 086d3f38:NotInit 086daeb8:098b99b8 << 

但是,從這裏,我不知道如何找對方法處理Tick事件。我懷疑它的東西做_coreTypeEventHelper,但是當我傾倒的是,我得到:

!do 098b99ac 
Name:  MS.Internal.CoreTypeEventHelper 
MethodTable: 0bfd3d0c 
EEClass:  0bc98420 
Size:  12(0xc) bytes 
File:  C:\Program Files (x86)\Microsoft Silverlight\4.0.50524.0\System.Windows.dll 
Fields: 
     MT Field Offset     Type VT  Attr Value Name 
00000000 40009f5  4      0 instance 098b9ae4 _eventAndDelegateTable 
506a0e94 40009f4  514   System.Int32 1 shared static _nextAvailableTableIndex 
    >> Domain:Value 086d3f38:NotInit 086daeb8:669 << 

然後我轉儲_eventAndDelegateTable:

Name:  System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]] 
MethodTable: 0bfcc0a0 
EEClass:  5026c744 
Size:  52(0x34) bytes 
File:  C:\Program Files (x86)\Microsoft Silverlight\4.0.50524.0\mscorlib.dll 
Fields: 
     MT Field Offset     Type VT  Attr Value Name 
5068f2d0 4000648  4  System.Int32[] 0 instance 098b9b18 buckets 
50691060 4000649  8 ...non, mscorlib]][] 0 instance 098b9b30 entries 
506a0e94 400064a  20   System.Int32 1 instance  1 count 
506a0e94 400064b  24   System.Int32 1 instance  1 version 
506a0e94 400064c  28   System.Int32 1 instance  -1 freeList 
506a0e94 400064d  2c   System.Int32 1 instance  0 freeCount 
50697f08 400064e  c ...Int32, mscorlib]] 0 instance 098b9650 comparer 
506ccfb0 400064f  10 ...Canon, mscorlib]] 0 instance 00000000 keys 
506ceaac 4000650  14 ...Canon, mscorlib]] 0 instance 00000000 values 
506a02e4 4000651  18  System.Object 0 instance 00000000 _syncRoot 
506895d8 4000652  1c ...SerializationInfo 0 instance 00000000 m_siInfo 

然後我那種輸了!

回答

1

在嘗試查找相關事件處理程序之前,您還可以通過調查爲什麼DispatcherTimer實例未獲得釋放來搜索泄漏源。
輸出!dumpheap -type DispatcherTimer後,在DispatcherTimer的幾個實例上執行!gcroot命令。您應該能夠看到哪個對象持有對定時器的引用。
此外,您可以放置​​適當的斷點(使用!bpmd),以獲得有用的堆棧跟蹤。

相關問題