XmlDocument.Load中的大内存泄漏(" filename"); [英] Big Memory Leak in XmlDocument.Load("filename");

查看:69
本文介绍了XmlDocument.Load中的大内存泄漏(" filename");的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用DevPartner 7.2跟踪内存泄漏,而我看到的是,我看到的是调用XmlDocument.Load()泄漏了大量内存。

当我单击测试表单上的按钮时,会调用以下代码。

(这是我编写的测试代码,用于确认错误,而不是我的实际代码)

private void button1_Click(object sender,System.EventArgs e)

{

XmlDocument xd = new XmlDocument();

for( int i = 0; i< 10; i ++)

{

xd.Load(" test.xml");

Thread .Sleep(1000);

}

}


" test.xml"是8525字节。


每次调用xd.Load(" test.xml")时,大约114,000字节是b / b
泄露。当我使用DevPartner GUI强制GC时,除了其中一个

之外的所有内容都被收集,但我仍然是114,000字节。在Sleep调用之后我试过把

System.GC.Collect(),但是行为没有改变。$ / b

我正在使用2003年,2005年修复此问题吗?有贴片吗?一个解决方法?


非常感谢任何信息。

I''ve been tracking down a memory leak using DevPartner 7.2 and what I
am seeing is that calling XmlDocument.Load() leaks A LOT of memory.

The following code is called when I click a button on my test form.
(this is test code I wrote to confirm the bug, not my actual code)
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument xd = new XmlDocument();
for ( int i = 0; i < 10; i++ )
{
xd.Load( "test.xml" ) ;
Thread.Sleep( 1000 );
}
}

"test.xml" is 8525 bytes.

Each time xd.Load( "test.xml" ) is called, approx 114,000 bytes are
leaked. When I force GC with the DevPartner GUI, all but one of those
are collected, but I am still out 114,000 bytes. I have tried putting
System.GC.Collect() after the Sleep call, but the behavior does not
change.

I am using 2003, does 2005 fix this? Is there a patch? A work around?

Any info greatly appreciated.

推荐答案

这可能是一个愚蠢的问题,但是你在调用GC之前是否将xd设置为空?

?否则仍然会有一个活跃的

参考,框架不会释放内存。

This might be a silly question, but are you setting xd to nothing
before calling the GC? Otherwise there will still be an active
reference, and the framework won''t release the memory.



" bleedledeep" < BL ********* @ yahoo.com>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...

"bleedledeep" <bl*********@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
我一直在使用DevPartner 7.2跟踪内存泄漏,我看到的是调用XmlDocument.Load()泄漏了大量内存。

以下当我单击测试表单上的一个按钮时调用代码。
(这是我编写的测试代码,用于确认错误,而不是我的实际代码)

private void button1_Click(object sender,System .EventArgs e)
{XmlDocument xd = new XmlDocument();
for(int i = 0; i< 10; i ++)
{x /。加载(test.xml);
Thread.Sleep(1000);
}
}

" test.xml"是8525字节。

每次调用xd.Load(test.xml)时,大约有114,000个字节被泄露。当我使用DevPartner GUI强制GC时,除了其中一个之外的所有
都被收集,但我仍然是114,000字节。我已经尝试在Sleep调用之后放入
System.GC.Collect(),但行为没有改变。

我使用的是2003,2005年是否解决了这个问题?有贴片吗?一个解决方法?

任何信息非常感谢。
I''ve been tracking down a memory leak using DevPartner 7.2 and what I
am seeing is that calling XmlDocument.Load() leaks A LOT of memory.

The following code is called when I click a button on my test form.
(this is test code I wrote to confirm the bug, not my actual code)
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument xd = new XmlDocument();
for ( int i = 0; i < 10; i++ )
{
xd.Load( "test.xml" ) ;
Thread.Sleep( 1000 );
}
}

"test.xml" is 8525 bytes.

Each time xd.Load( "test.xml" ) is called, approx 114,000 bytes are
leaked. When I force GC with the DevPartner GUI, all but one of those
are collected, but I am still out 114,000 bytes. I have tried putting
System.GC.Collect() after the Sleep call, but the behavior does not
change.

I am using 2003, does 2005 fix this? Is there a patch? A work around?

Any info greatly appreciated.




他们没有泄露,GC还没有恢复它们。

当HE决定是时候做
时,GC会收集未引用的对象,所以调用GC.Collect()来强制收集通常是非常糟糕的

想法。


Willy。



They are not leaked, the GC did not yet recover them.
The GC will collect the unreferenced objects when HE decides it''s time to do
so, calling GC.Collect() to force a collection is in general a very bad
idea.

Willy.


我想再次调用Load()会导致xd到

清除旧的东西并只引用新的东西,但是,

这是一个有趣的尝试:


如果我执行以下操作,那么114,000s不会堆积,但我仍然没有b / b
永远不会摆脱最后一个。


for(int i = 0; i< 10; i ++)

{

XmlDocument xd = new XmlDocument();

xd .Load(" test.xml");

Thread.Sleep(1000);

xd = null;

System.GC。收集();

}

In请注意,只需调用XmlDocument xd = new

XmlDocument();似乎泄漏了内存,但它是一个固定的592字节 -

并不重要你称它多少次。

I would like to think that calling Load() again would cause the xd to
clear out the old stuff and have only references to the new stuff, but,
that is an interesting thing to try:

If I do the following, then the 114,000s don''t pile up, but I still
never get rid of the last one.

for ( int i = 0; i < 10; i++ )
{
XmlDocument xd = new XmlDocument();
xd.Load( "test.xml" ) ;
Thread.Sleep( 1000 );
xd = null;
System.GC.Collect();
}
Interesting to note that just calling XmlDocument xd = new
XmlDocument(); seems to leak memory, but it is a fixed 592 bytes -
doesn''t matter how many times you call it.


这篇关于XmlDocument.Load中的大内存泄漏(&quot; filename&quot;);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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