>>用Clear方法可以释放掉这个地址吗?
不会。Tlist的Item内保存的是某个指针或类的地址,clear方法只将Item的值清空,不会释放其他与Item内容有关的内存,释放这些内存应由当初的分配者来干。

解决方案 »

  1.   

    不行!
    你的先将Item里面的东东Free掉,再Clear
      

  2.   

    先clear,再free,在令它 为nil.
      

  3.   

    kylix2001是对的。
    具体去看TList的clear的源码
      

  4.   

    Tiem.Data指向的内存要自己释放,其他的没事!
      

  5.   

    Delphi的帮助对TList.Clear如是说的:
    Call Clear to empty the Items array and set the Count to 0. Clear also frees the memory used to store the Items array and sets the Capacity to 0.
    很明显,并没有释放指向的对象。
    Delphi在Classes中:
    procedure TList.Clear;
    begin
      SetCount(0);
      SetCapacity(0);
    end;
    其中用了TList.Delete(Index: Integer);如下:
    procedure TList.Delete(Index: Integer);
    var
      Temp: Pointer;
    begin
      if (Index < 0) or (Index >= FCount) then
        Error(@SListIndexError, Index);
      Temp := Items[Index];
      Dec(FCount);
      if Index < FCount then
        System.Move(FList^[Index + 1], FList^[Index],
          (FCount - Index) * SizeOf(Pointer));  //从这里可以明显的看到,只是将指针的资源回收了,指向的对象没有回收啊
      if Temp <> nil then
        Notify(Temp, lnDeleted);
    end;
    是不是这样:
    for index := 0 to AList.Count - 1 do
      TSomeObject(AList[Index]).Free;
    然后再TList.Clear或者TList.Free呢,应该是这样的吧?
      

  6.   

    如果是对象的指针,要FREE。如果是结构或变量的指针,不FREE。