如果tstringlist中存放了非简单类型,比如是某个class类型,你只free掉tstringlist是不行的,在fee掉sttringlist之前你要先释放掉那些对像,类似于下面的ClearDeptListprocedure TfrmUser.CreateDeptList; procedure AddXmlNodeTofcTree(tn: TTreeNode; xn: IXMLNode); var OrgNO: PNode_XML; ChildNode: IXMLNode; CurrentTN: TTreeNode; begin New(OrgNO); OrgNO^.Name := xn.Attributes['name']; OrgNO^.NO := xn.Attributes['orgno']; OrgNO^.NodeType := 1; CurrentTN := tvDept.Items.AddChildObject(tn, OrgNO^.Name, OrgNO); ChildNode := xn.ChildNodes.First; while (ChildNode <> nil) do begin AddXmlNodeTofcTree(CurrentTN, ChildNode); ChildNode := ChildNode.NextSibling; end; end;var st: TStringStream; str: String; Root, ChildNode: IXMLNode; i: Integer;begin for i := 0 to tvDept.Items.Count - 1 do Dispose(Pointer(tvDept.Items.Data)); tvDept.Items.Clear; {$IFDEF XMLDEBUG} str := GetStrFromXML('Dept.xml'); {$ELSE} str := IdHttpUser.Get(findAllOrg); {$ENDIF} XDUser.XML.Clear; st := TStringStream.Create(str); try XDUser.LoadFromStream(st, xetUTF_8); Root := XDUser.DocumentElement; if Root = nil then Exit; ChildNode := Root.ChildNodes.First; while (ChildNode <> nil) do begin AddXmlNodeTofcTree(nil, ChildNode); ChildNode := ChildNode.NextSibling; end; finally st.Free; end;end;procedure TfrmUser.ClearDeptList;var i: Integer;begin for i := 0 to tvDept.Items.Count - 1 do Dispose(tvDept.Items.Data); tvDept.Items.Clear;end;