Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IXMLDocument memory leak?

889 views
Skip to first unread message

Chris Ogle

unread,
Jun 16, 2004, 11:42:32 AM6/16/04
to
...or just operator malfunction?

In Delphi 7 Enterprise, I use IXMLDocument to load an XML file.
Task Manager says memory is allocated when I set Active to True,
which sounds right to me. IXMLDocument should be automatically
destroyed when it goes out of scope, but Task Manager says the
memory is still allocated.

I must be doing something wrong. Please show me the error of
my ways.

Chris

-----------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
Metafile : IXMLDocument;
begin
// Create & initialize IXMLDocument.
// Have also tried: Metafile := LoadXMLDocument( 'Metadata.xml' );
Metafile := TXMLDocument.Create( nil );
Metafile.FileName := 'Metadata.xml';

// Populate the IXMLDocument. This allocates lots of memory.
Metafile.Active := True;

// Shouldn't have to do anything else to release the IXMLDocument, but...

// Try removing all child nodes to release memory.
while Metafile.DOMDocument.firstChild <> nil do
Metafile.DOMDocument.removeChild( Metafile.DOMDocument.firstChild );

// Try explicitly releasing the IXMLDocument.
Metafile._Release;

// Try forcing the reference count to zero.
Metafile := nil;

// Nope. Even after exiting here, memory is still allocated.
end;


-----------------------------------------------------
This message was posted using http://www.gdse.com/

George Kashperko

unread,
Jun 17, 2004, 11:07:27 AM6/17/04
to
Hi, Chris.

Task manager isn't a goot tool to profile apps' memory usage - u can't rely
on it reports making decisions wether your app have memory leaks or not. Use
special tools instead.

Good luck.


Chris Ogle

unread,
Jun 18, 2004, 9:52:01 AM6/18/04
to
George,

Thanks for the reply. Can you suggest a good tool I can use?

Chris

Bruce McGee

unread,
Jun 18, 2004, 10:07:08 AM6/18/04
to
Chris Ogle wrote:

> ...or just operator malfunction?
>
> In Delphi 7 Enterprise, I use IXMLDocument to load an XML file.
> Task Manager says memory is allocated when I set Active to True,
> which sounds right to me. IXMLDocument should be automatically
> destroyed when it goes out of scope, but Task Manager says the
> memory is still allocated.
>
> I must be doing something wrong. Please show me the error of
> my ways.
>
> Chris

[...]

Hi Chris,

I ran into something similar using IXMLDocument and IXMLDOMDocument.
It was frustrating, because we could only see the memory usage growing
using the Windows task manager. George is right that this isn't the
best tool for detecting memory leaks, but it's plenty accurate enough
to tell me that the machine is out of RAM and that my app is the
culprit. So you aren't entirely crazy.

Turns out the problem showed up on Windows 2000. We solved it by
upgrading the MSXML 3.0 that shipped with Windows 2000 to SP2. I see
they have SP4 available now. I think this update is also installed if
you get the latest IE6 patches.

http://www.microsoft.com/downloads/details.aspx?FamilyID=c0f86022-2d4c-4
162-8fb8-66bfc12f32b0&DisplayLang=en

Let me know if this helps.

--
Regards,
Bruce McGee
Glooscap Software

George Kashperko

unread,
Jun 18, 2004, 10:43:54 AM6/18/04
to
Hi, Chris.

Try to search in google with "Delphi memory profiling".

Good luck.


Jurgen Simons

unread,
Jul 5, 2004, 10:22:06 AM7/5/04
to
Bruce,
Chris,

I have the same memory problem. I have W2000 SP4 installed, but the problem
still exist. Do you have other solutions?

Further, setting Active to True costs lots of CPU. Is this normal? I should
deal with 1000 XMLDocuments per second. Is this to much for the DOM or am I
doing something wrong? When I get the information out of the XML by
stringoperations, it only takes a fraction of the CPU, even for 1000
documents per second.

Regards,

Jurgen

"Bruce McGee" <bmc...@glooscap.com> wrote in message
news:xn0djnxm7...@newsgroups.borland.com...

Petr Vones

unread,
Jul 5, 2004, 3:31:19 PM7/5/04
to
"Jurgen Simons" <jsimon...@yucom.be> wrote in message

> I have the same memory problem. I have W2000 SP4 installed, but the problem
> still exist. Do you have other solutions?

Install MSXML4 update:
http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&DisplayLang=en

Petr.


Bruce McGee

unread,
Jul 6, 2004, 8:14:20 AM7/6/04
to
Jurgen Simons wrote:

> Bruce,
> Chris,
>
> I have the same memory problem. I have W2000 SP4 installed, but the
> problem still exist. Do you have other solutions?
>
> Further, setting Active to True costs lots of CPU. Is this normal? I
> should deal with 1000 XMLDocuments per second. Is this to much for
> the DOM or am I doing something wrong? When I get the information out
> of the XML by stringoperations, it only takes a fraction of the CPU,
> even for 1000 documents per second.
>
> Regards,
>
> Jurgen

I solved this by installing a service pack of MSXML3, or as Petr
suggested, install MSXML4. Chris mentioned that MSXML4 solved his
problem.

Please let us know how you make out.

Jurgen Simons

unread,
Jul 6, 2004, 9:33:59 AM7/6/04
to
Installing MSXML4 solved all CPU and memory problems! Thanks!

Jurgen

"Bruce McGee" <bmc...@glooscap.com> wrote in message

news:xn0dkfxzl...@newsgroups.borland.com...

sold...@gmail.com

unread,
Jul 11, 2014, 4:10:39 PM7/11/14
to
Hi Chris,

I just recently ran into this problem, and what solved the problem for me was setting

//Using your XML variable
metafile.active:=false;

I am also using IXMLDocument, and doing that releases the document from memory. No extra installs, no extra tools, works perfectly.

When trying to determine memory leaks in my program, I always set:

ReportMemoryLeaksOnShutDown:=True;

as the first line of code in my DPR file to catch anything and everything.

Hope this helps you in the future.

Barajas, Carlos
0 new messages