I
it80
Unregistered / Unconfirmed
GUEST, unregistred user!
type
Pa=^Ta;
Ta=Record
a1:string[60]
a2:Tb;
a3:Tlist
//存放Pb型数据,数量不定
end;
Pb=^Tb
Tb=real;
Tc=class
private
public
aList:TList
//存放Pa型数据,数量不定
constructor Create
overload;
destructor Destroy
override;
procedure Free;
procedure Reflash;
procedure loadfile(const name: string);
procedure savefile;
end;
------
//在退出程序 时
i:=Tc.aList.Count;
if i>0 then
begin
for n:=0 to i-1 do
begin
m:=Pa(Tc.aList.Items[n]).a3.Count;
for j:=0 to m-1 do
begin
Dispose(Pa( Tc.aList.Items[n]).a3.Items[j])
end;
end;
// Dispose(Tc.aList.Items[n])
//会出错
end;
这样仅嵌套一次就存在内存泄漏,若更多嵌套(若pb是类似pa那样含有tlist)就更严重了,请各位帮忙整理一下
Pa=^Ta;
Ta=Record
a1:string[60]
a2:Tb;
a3:Tlist
//存放Pb型数据,数量不定
end;
Pb=^Tb
Tb=real;
Tc=class
private
public
aList:TList
//存放Pa型数据,数量不定
constructor Create
overload;
destructor Destroy
override;
procedure Free;
procedure Reflash;
procedure loadfile(const name: string);
procedure savefile;
end;
------
//在退出程序 时
i:=Tc.aList.Count;
if i>0 then
begin
for n:=0 to i-1 do
begin
m:=Pa(Tc.aList.Items[n]).a3.Count;
for j:=0 to m-1 do
begin
Dispose(Pa( Tc.aList.Items[n]).a3.Items[j])
end;
end;
// Dispose(Tc.aList.Items[n])
//会出错
end;
这样仅嵌套一次就存在内存泄漏,若更多嵌套(若pb是类似pa那样含有tlist)就更严重了,请各位帮忙整理一下