我用D7自带的XML生成向导,根据XML文件自动生成了接口,其中有3个全局的方法:
function GetBatch(Doc: IXMLDocument): IBatchObjType;
function LoadBatch(const FileName: WideString): IBatchObjType;
function NewBatch: IBatchObjType;
我为了和以前的程序兼容,在Root接口外面包了一个类定义,
在类中定义了一个XMLDocument控件用于动态创建,还有1个Root接口FBatch,类型是root接口IBatchObj
我在类中实现了Create函数和Destroy函数,结果我创建类,使用一些方法,再释放,然后再重新创建,再使用,在释放结果内存占用越来越大,知道应用程序关闭才释放,我把接口都设置为nil了,但是就是没有释放。我认为还是接口没有释放,但是就是不知道哪里出问题了,代码如下:
TBatchObj=class(TObject) private
FXMLDoc: TXMLDocument;
FComponent:TComponent;
FBatch : IBatchObjType; //Batch接口
public //加载XML,并设置相应的Frame。
//如果参数isFile为true,则参数AXML为XML文件全路径名称;否则为XML内容
//参数:CreateFrameType创建Frame的类型,默认为动态创建
//参数:UseDocFrame是否启用DocFrame,默认不起用
//参数:UserPageFrame是否启用PageFrame,默认不起用
//参数:OneFrameDocsCount一个DocFrame中Doc的数量,默认为10
//参数:OneFramePagesCount一个PageFrame只Page的数量,默认为1000
constructor Create(AXML:String='';isFile:boolean=True;
UseDocFrame:Boolean=false;UsePageFrame:Boolean=false;
OneFrameDocsCount:Integer=OneFrameDocsCountDefaultValue;
OneFramePagesCount:Integer=OneFramePagesCountDefaultValue;
CreateFrameType:TCreateFrameType=cfDynamic);overload;
destructor Destroy;override;
...end;实现如下:
constructor TBatchObj.Create(AXML:String='';isFile:boolean=True;
UseDocFrame:Boolean=false;UsePageFrame:Boolean=false;
OneFrameDocsCount:Integer=OneFrameDocsCountDefaultValue;
OneFramePagesCount:Integer=OneFramePagesCountDefaultValue;
CreateFrameType:TCreateFrameType=cfDynamic);
var
i:integer;
begin
inherited Create;
FComponent:=TComponent.Create(nil);
FXMLDoc:=TXMLDocument.Create(FComponent); if isFile then
//FxmlDoc.LoadFromFile(AXML)
FxmlDoc.FileName := AXML
else
Fxmldoc.XML.Text := AXML;
for i:=0 to DocCount-1 do
begin
self.FBatch.Document[i].SetOwner(self);
end; end;
destructor TBatchObj.Destroy;
begin
if FXMLDoc<>nil then
begin
FXMLDoc.Free;
FXMLDoc:=nil;
end;
FComponent.Free;
FComponent:=nil; FBatch:=nil;//Root接口,这个地方应该可以释放啊?为啥不释放内存呢 inherited;
end;主程序调用,如:
for i:=0 to 20 do
begin
MyBatch:=TBatch.Create(openDialog.filename);
MyBatch....
MyBatch.Free;
end;
function GetBatch(Doc: IXMLDocument): IBatchObjType;
function LoadBatch(const FileName: WideString): IBatchObjType;
function NewBatch: IBatchObjType;
我为了和以前的程序兼容,在Root接口外面包了一个类定义,
在类中定义了一个XMLDocument控件用于动态创建,还有1个Root接口FBatch,类型是root接口IBatchObj
我在类中实现了Create函数和Destroy函数,结果我创建类,使用一些方法,再释放,然后再重新创建,再使用,在释放结果内存占用越来越大,知道应用程序关闭才释放,我把接口都设置为nil了,但是就是没有释放。我认为还是接口没有释放,但是就是不知道哪里出问题了,代码如下:
TBatchObj=class(TObject) private
FXMLDoc: TXMLDocument;
FComponent:TComponent;
FBatch : IBatchObjType; //Batch接口
public //加载XML,并设置相应的Frame。
//如果参数isFile为true,则参数AXML为XML文件全路径名称;否则为XML内容
//参数:CreateFrameType创建Frame的类型,默认为动态创建
//参数:UseDocFrame是否启用DocFrame,默认不起用
//参数:UserPageFrame是否启用PageFrame,默认不起用
//参数:OneFrameDocsCount一个DocFrame中Doc的数量,默认为10
//参数:OneFramePagesCount一个PageFrame只Page的数量,默认为1000
constructor Create(AXML:String='';isFile:boolean=True;
UseDocFrame:Boolean=false;UsePageFrame:Boolean=false;
OneFrameDocsCount:Integer=OneFrameDocsCountDefaultValue;
OneFramePagesCount:Integer=OneFramePagesCountDefaultValue;
CreateFrameType:TCreateFrameType=cfDynamic);overload;
destructor Destroy;override;
...end;实现如下:
constructor TBatchObj.Create(AXML:String='';isFile:boolean=True;
UseDocFrame:Boolean=false;UsePageFrame:Boolean=false;
OneFrameDocsCount:Integer=OneFrameDocsCountDefaultValue;
OneFramePagesCount:Integer=OneFramePagesCountDefaultValue;
CreateFrameType:TCreateFrameType=cfDynamic);
var
i:integer;
begin
inherited Create;
FComponent:=TComponent.Create(nil);
FXMLDoc:=TXMLDocument.Create(FComponent); if isFile then
//FxmlDoc.LoadFromFile(AXML)
FxmlDoc.FileName := AXML
else
Fxmldoc.XML.Text := AXML;
for i:=0 to DocCount-1 do
begin
self.FBatch.Document[i].SetOwner(self);
end; end;
destructor TBatchObj.Destroy;
begin
if FXMLDoc<>nil then
begin
FXMLDoc.Free;
FXMLDoc:=nil;
end;
FComponent.Free;
FComponent:=nil; FBatch:=nil;//Root接口,这个地方应该可以释放啊?为啥不释放内存呢 inherited;
end;主程序调用,如:
for i:=0 to 20 do
begin
MyBatch:=TBatch.Create(openDialog.filename);
MyBatch....
MyBatch.Free;
end;
FBatch := GetBatch(Fxmldoc);
我用的是TXMLDocument控件和dalphi自带的XML Data Binding向导,然后我的自动生成的接口中增加了一些新的接口,在自动生成的类中添加了一些属性,难道他们出了问题???自动生成的代码不能手工修改?