EOutOfMemory使用Delphi创建大型XML [英] EOutOfMemory Creating Large XML Using Delphi

查看:154
本文介绍了EOutOfMemory使用Delphi创建大型XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi从关系数据库中的数据创建XML文档。它可以在小型数据集上进行很好的测试,但是当我尝试将数据集的大小扩展到生产级别时,它最终在创建节点的过程中因EOutOfMemory异常而被炸毁。

I'm using Delphi to create an XML document from data in a relational database. It tests fine with small datasets, but when I try to expand the size of the data set to production levels it eventually bombs out with an EOutOfMemory exception during node creation.

I我正在使用放在表格上的TXMLDocument(以MSXML作为供应商),我的代码通常如下所示:

I'm using a TXMLDocument dropped on a form (MSXML as the Vendor), and my code generally looks like this:

  DS := GetDS(Conn, 'SELECT Fields. . . FROM Table WHERE InsuredID = ' +IntToStr(AInsuredID));

  try

    while not DS.Eof do
      with ANode.AddChild('LE') do
      begin
        AddChild('LEProvider').Text := DS.FieldByName('LEProvider').AsString;
        // Need to handle "other" here
        AddChild('Date').Text       := DateToXMLDate(DS.FieldByName('LEDate').AsDateTime);
        AddChild('Pct50').Text      := DS.FieldByName('50Percent').AsString;
        AddChild('Pct80').Text      := DS.FieldByName('80Percent').AsString;
        AddChild('Actuarial').Text  := DS.FieldByName('CompleteActuarial').AsString;
        AddChild('Multiplier').Text := DS.FieldByName('MortalityMultiplier').AsString;
        DS.Next;
      end;

  finally

    DS.Free;

  end;

此部分以及适用于不同数据库表的许多其他类似构造的部分执行了很多次。在此示例中,ANode是传递给函数的IXMLNode,用作容器。

with this section, as well as numerous other similarly constructed sections applying to different database tables, executed many times. In this example ANode is an IXMLNode passed in to the function for use as a container.

我不希望磁盘上生成的XML文件超过10兆字节。我以为我在创建和处置XMLNode时会以某种方式泄漏内存,但是我对Interfaces不够熟悉,无法知道如何解决我的问题。

I do not expect the resulting XML file on disk to be more than 10 megabytes. I assume that somehow I'm leaking memory in my creation and disposal of XMLNodes, but I'm not familiar enough with Interfaces to know how to track down my problem.

推荐答案

TXMDocument是DOM样式的接口,可将整个文档保留在内存中。这样内存很快就用完了。即使生成的文件不是那么大。您实际上并不需要TXMLDocument来写出简单的XML。为什么不直接以xml格式写入文件?

TXMDocument is a DOM style interface and keeps the whole document in memory. Memory gets used up rather quick that way. Even when the resulting file is not that big. You don't really need TXMLDocument to write out a simple XML. Why not write directly to a file in xml format?

话虽这么说:由于堆碎片,这也可能是错误,或者是真正的内存泄漏。您可能要尝试使用此处提到的工具:用于Delphi的Profiler和内存分析工具

That being said: It could also be an error due to heap fragmentation or be a real memory leak. You might want to try a tool like mentioned here: Profiler and Memory Analysis Tools for Delphi

这篇关于EOutOfMemory使用Delphi创建大型XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆