2009-04-13 41 views
12

有哪些工具可用於將VB6應用程序中的內存消耗歸入多個組件? 例如,在Process Explorer中,我可以通過觀察各種計數器(專用字節,工作集等)來獲取整個應用程序佔用的內存。我想深入一些,並瞭解在運行時創建的各種組件或對象佔用了多少內存。例如,計算在運行時緩存數據的大集合佔用多少內存,以及它如何根據集合中元素的數量進行更改。用於識別VB6應用程序中內存耗盡的工具

回答

2

我不確定任何公開的(免費)工具都會將VB6代碼剖析到模塊級別。有幾種內存分析器可用於C/C++和.NET,但在VB6上看不到很多內存分析器。看起來這個領域的所有舊供應商(IBM Purify,Compuware Devpartner/Boundschecker)都已被收購,或者只能轉移到.NET支持。

您可能會嘗試GlowCode。它聲明C++支持,但也強調Win32本機x86映像。

微軟發佈DebugDiag,它支持.NET或Win32的內存泄漏檢測,儘管我從來沒有用過VB。它可能不會向模塊級別顯示出色的分配,但我敢打賭,它至少會確定哪些庫/ dll分配了最多的內存。

1

MS站點上還有一個名爲processmonitor.exe的工具。它會報告每個請求調用,並且您可以使用其過濾功能來只監視應用程序的進程請求。

+0

此工具不能深入進程監視器,因爲它不知道VB6內存使用情況。 – 2011-06-27 20:06:10

5

我最喜歡的工具必須是DevPartner,雖然在1,500英鎊的流行音樂它並不便宜。它雖然比內存泄漏檢查要多得多,但如果這就是你所需要的,你可能是地毯式轟炸螞蟻。

如果您想查看您的應用程序是否正確釋放資源,請使用我寫的函數將內存轉儲到給定位置。我首先會緩存每個變量的地址,然後在關閉時可以調用DumpVariableMemory傳遞這些位置的引用來查看它們是否已被釋放。

如果您還沒有一個已經,你需要添加一個聲明FOPR CopyMemory的太:)

Public Function DumpVariableMemory(ByVal lngVariablePointer&, _ 
            ByVal lngBufferSizeInBytes&) As String 
    '' * Object Name: DumpVariableMemory 
    '' * Type:   Function 
    '' * Purpose:  Returns a memory dump of the variable or pointer location 
    '' * Created:  21/08/2006 - 17:41:32 
    '' * Coder:   Richard Pashley - NUPUK00008148 
    '' * Build Machine: W-XPRP-77 
    '' * Encapsulation: Full 
    '' * Parameters: lngVariablePointer  - Long - Pointer to the data to dump 
    '' *    lngBufferSizeInBytes - Long - Size of the dump to ouput in bytes 
    '' * Returns:  -      - String - Memory dump output as a string 
    '' *    This will dump the memory location starting at the pointer address and 
    '' *    ending at the address plus the offset (lngBufferSizeInBytes). 
    '' *    You can use LenB to determine the size of the variable for the 
    '' *    lngBufferSizeInBytes parameter if required. 
    '' *    Example: DebugPrint DumpVariableMemory(VarPtr(lngMyLongValue),LenB(lngMyLongValue) 
    '' * Modified By: [Name] 
    '' * Date:   [Date] 
    '' * Reason:  [NUPUKxxxxxxxxx] 
    '' Declare locals 
    Dim lngBufferIterator&     '' Buffer iterator 
    Dim lngBufferInnerIterator&    '' Buffer loop inner iterator 
    Dim bytHexDumpArray() As Byte   '' Received output buffer 
    Dim strDumpBuffer$      '' Formatted hex dump construction buffer 
    Dim lngValidatedBufferSize&    '' Validated passed buffer size 
    '' Turn on error handling 
    On Error GoTo DumpVariableMemory_Err 
    '' Resize output buffer 
    ReDim bytHexDumpArray(0 To lngBufferSizeInBytes - 1) As Byte 
    '' Retrieve memory contents from supplied pointer 
    Call CopyMemory(bytHexDumpArray(0), _ 
     ByVal lngVariablePointer, _ 
     lngBufferSizeInBytes) 
    '' Format dump header 
    strDumpBuffer = String(81, "=") & vbCrLf & _ 
     "Pointer Address = &h" & Hex$(lngVariablePointer) & _ 
     " Ouput Buffer Size = " & FormatBytes(lngBufferSizeInBytes) 
    '' Add header seperator 
    strDumpBuffer = strDumpBuffer & _ 
     vbCrLf & String(81, Chr$(61)) 
    '' Validate buffer dimensions 
    If lngBufferSizeInBytes Mod 16 = 0 Then 
     '' Validated ok so assign 
     lngValidatedBufferSize = lngBufferSizeInBytes 
    Else 
     '' Refactor to base 16 
     lngValidatedBufferSize = _ 
      ((lngBufferSizeInBytes \ 16) + 1) * 16 
    End If 
    '' Iterate through buffer contents 
    For lngBufferIterator = 0 To (lngValidatedBufferSize - 1) 
     '' Determine if first row 
     If (lngBufferIterator Mod 16) = 0 Then 
      '' Format dump output row 
      strDumpBuffer = strDumpBuffer & vbCrLf & Right$(String(8, Chr$(48)) _ 
       & Hex$(lngVariablePointer + lngBufferIterator), 8) & Space(2) & _ 
       Right$(String(4, Chr$(48)) & Hex$(lngBufferIterator), 4) & Space(2) 
     End If 
     '' Determine required dump buffer padding 
     If lngBufferIterator < lngBufferSizeInBytes Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Right$(Chr$(48) & _ 
       Hex(bytHexDumpArray(lngBufferIterator)), 2) 
     Else 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(2) 
     End If 
     '' Determine required dump buffer padding 
     If (lngBufferIterator Mod 16) = 15 Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(2) 
      '' Iterate through buffer row 
      For lngBufferInnerIterator = (lngBufferIterator - 15) To lngBufferIterator 
       '' Validate row width 
       If lngBufferInnerIterator < lngBufferSizeInBytes Then 
        '' Validate buffer constraints 
        If bytHexDumpArray(lngBufferInnerIterator) >= 32 And _ 
         bytHexDumpArray(lngBufferInnerIterator) <= 126 Then 
         '' Ouput data to dump buffer row 
         strDumpBuffer = strDumpBuffer & _ 
          Chr$(bytHexDumpArray(lngBufferInnerIterator)) 
        Else 
         '' Pad dump buffer 
         strDumpBuffer = strDumpBuffer & Chr$(45) 
        End If 
       End If 
      Next 
      '' Determine required dump buffer padding 
     ElseIf (lngBufferIterator Mod 8) = 7 Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Chr$(45) 
     Else 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(1) 
     End If 
    Next 
    '' Assign result to function output 
    DumpVariableMemory = strDumpBuffer & _ 
     vbCrLf & String(81, Chr$(61)) & vbCrLf 
Exit_Point: 
    Exit Function 
    '' Error Handling 
DumpVariableMemory_Err: 
    LogError "modNYFixLibrary.DumpVariableMemory", Err.Number, Err.Description 
    DumpVariableMemory = String(81, Chr$(61)) & vbCrLf & _ 
     "DumpFailed!" & vbCrLf & String(81, Chr$(61)) 
    GoTo Exit_Point 
    Resume 
End Function 
2

Memory Validator可以告訴你內存在VB6程序分配(和泄露)(和C++,C,Delphi,Fortran 95 ...)。