关于内存和资源泄露的第三方工具,我用了MemProof、Sleuth CodeWatch 3
和BoundsChecker来测试我的程序,但均发现报告DELPHI5、6中有许多内存和
资源泄露,在许多VCL库中都有,如Graphics、Controls、Forms、System等,
主要错误有Live pointer、Virtual memory、Pen、Brush、Font
MemProof对于Live pointer的错误定位,举个例子:
***Graphics for d5***
function TResourceManager.AllocResource(const ResData): PResource;
var
  ResHash: Word;
begin
  ResHash := GetHashCode(ResData, ResDataSize);
  Lock;
  try
    Result := ResList;
    while (Result <> nil) and ((Result^.HashCode <> ResHash) or
      not CompareMem(@Result^.Data, @ResData, ResDataSize)) do
      Result := Result^.Next;
    if Result = nil then
    begin
      GetMem(Result, ResDataSize + ResInfoSize); ****软件定位于这行
      with Result^ do
      begin
        Next := ResList;
        RefCount := 0;
        Handle := TResData(ResData).Handle;
        HashCode := ResHash;
        Move(ResData, Data, ResDataSize);
      end;
      ResList := Result;
    end;
    Inc(Result^.RefCount);
  finally
    Unlock;
  end;
end;
软件建议用FreeMem释放,但我在finally后面加入FreeMem(Result)以后再用MemProof
还是一样
还有Virtual memory错误,软件建议VirtualFree由VirtualAlloc释放...
还请高人指点个中奥妙!

解决方案 »

  1.   

    delphi有自己的堆管理方法,
    你应该Free后再Create看消耗内存有没增加,
    而不应该Free后看内存是否减小。
      

  2.   

    不会吧,我想MemProof报的是内存泄露,我不是FREE后看内存是否减少,我只是想解决内存泄露问题 
      

  3.   

    我用D7的,D5管他呢
    MemProof也不一定可靠的,Borland不会那么傻吧?有问题都不知道?
      

  4.   

    To:
      ly_liuyang(Liu Yang) 
    老兄,MemProof也不一定可靠,但Sleuth CodeWatch呢,它可是连续3年夺得
    国外第三方软件评测第一名,BoundsChecks也是大名鼎鼎!
      

  5.   

    TResourceManager.AllocResource分配的内存,自然由TResourceManager.FreeResource来释放,这两个配对使用没问题啊,没有用过这些软件,但是总不能因为在一个过程里发现GetMem但没有发现
    FreeMem就说是泄漏。li_liuyang说的"Borland不会那么傻吧?有问题都不知道?"问题是Borland他明知有问题也不管!别的不说,单单说dbexpress, Delphi 7的Release Notes上说:
    MSSQL driver - Known issues
    ---------------------------
    2) Master detail:   a) When trying to open a master-detail as a nested
          dataset and if the detail link field is an INTEGER
          type and defined NOT NULL you will get a SQL Error
          "SQL State:HY000, SQL Error Code: 0, Invalid Input
          parameter values. Check the status values for
          details"      A patch will be made available >>>soon<<< at Borland's
          support download site.
    直到去年10月份发布MSSQL Driver Update也没有解决这个问题,你说这个问题不解决,它又不公开源码,MSSQL Driver for dbexpress 怎么用?