内存泄漏 [英] Memory Leaks

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

问题描述

你好,


我在VB.Net 2005中创建了一个Windows服务应用程序。该服务是非常基本的,它使用System.Timers .Timer类来轮询数据库,

检查要执行的作业。找到工作后,

System.Timers.ElapsedEventHandler创建一个新线程来执行工作。


工作非常基础,它使用和xml使用XSLTransform类将文档应用于XSLT

文档。


此服务运行后,内存翻倍,并继续加倍

直到它最终在内存上崩溃。当我分析这个应用程序时,我发现
注意到Byte []类占用的内存最多,并且在所有后续垃圾收集中幸存下来。我将Byte []固定到以下

方法:


私有_XSLTDocument为Xml.Xsl.XslTransform


Private Sub InitializeTemplate(ByVal aXSLTLocation As String)


Dim xsltFileSpec As String


如果IO.File.Exists(aXSLTLocation)那么

_XSLTDocument = New Xml.Xsl.XslTransform

_XSLTDocument.Load(xsltFileSpec,New Xml.XmlUrlResolver)

Else

抛出新的IO.FileNotFoundException(String.Format(" No XLS

转换文档位于:{0}。),xsltFileSpec))

结束如果


结束子


看来(对我来说)XSLTransform类没有被收集或是

没有发布它占据的记忆。对于持有这种方法的类,我已经暗示了IDosposable

接口(虽然,我不明白为什么需要

,但我试图解决这个问题) 。我已经确定

完成后,这个类运行的线程确实处于停止状态。我已经耗尽了我的潜力,这里的任何帮助都将是

赞赏。


底线:为什么XSLTransform类的Load方法占用了?br />
这么多内存,我该怎么发布?


谢谢。


Malcolm Klotz


Hello,

I have created a Windows Service application in VB.Net 2005. The service is
pretty basic, it uses the System.Timers.Timer class to poll a database that
checks for jobs to perform. Upon finding a job, the
System.Timers.ElapsedEventHandler creates a new thread to execute the job.

The job is pretty basic, it uses and xml document and applies it to an XSLT
document using the XSLTransform class.

After this services runs a job the memory doubles, and keeps on doubling
until it finally crashes on memory. When I profiled this application, I
noticed the the Byte[] class was holding the most memory, and was surviving
all subsequent garbage collections. I pinned the Byte[] to the following
method:

Private _XSLTDocument As Xml.Xsl.XslTransform

Private Sub InitializeTemplate(ByVal aXSLTLocation As String)

Dim xsltFileSpec As String

If IO.File.Exists(aXSLTLocation) Then
_XSLTDocument = New Xml.Xsl.XslTransform
_XSLTDocument.Load(xsltFileSpec, New Xml.XmlUrlResolver)
Else
Throw New IO.FileNotFoundException(String.Format("No XLS
Transform document was found at: {0}.", xsltFileSpec))
End If

End Sub

It appears (to me) that the XSLTransform class is not being collected or is
not releasing the memory it occupies. I have impliemented the IDosposable
interface for the class that holds this method (although, I do not see why
it was needed, but I was trying to fix the problem). I have made sure that
the thread the this class runs on is indeed at a stopped state when
completed. I have exhausted my potentional, any help here would be
appreciated.

Bottom line: Why is the the Load method on the class XSLTransform taking up
so much memory, and how do I release it?

Thanks.

Malcolm Klotz


推荐答案

奇怪。 XslTransform类没有实现IDisposable,因此它只需要包含托管资源,因此应该可以由垃圾收集器处理



XslTransform类在框架2.0中已过时。您应该使用

XslCompiledTransform类。


Malcolm Klotz写道:
Strange. The XslTransform class doesn''t implement IDisposable, so it
should only contain managed resources, and thus should be able to be
handled by the garbage collector.

The XslTransform class is obsolete in framework 2.0. You should use the
XslCompiledTransform class instead.

Malcolm Klotz wrote:
你好,

我在VB.Net 2005中创建了一个Windows服务应用程序。该服务非常基本,它使用System.Timers.Timer类来轮询数据库,以检查要执行的作业。找到作业后,
System.Timers.ElapsedEventHandler创建一个新线程来执行作业。

作业非常基础,它使用和xml文档并将其应用于XSLT <使用XSLTransform类的文档。

此服务运行后,内存会翻倍,并继续加倍,直到它最终崩溃在内存中。当我分析这个应用程序时,我注意到Byte []类占用了最多的内存,并且在所有后续的垃圾收集中幸存下来。我将Byte []固定到以下
方法:

Private _XSLTDocument As Xml.Xsl.XslTransform
私有Sub InitializeTemplate(ByVal aXSLTLocation As String)

Dim xsltFileSpec As String

如果IO.File.Exists(aXSLTLocation)那么_XSLTDocument = New Xml.Xsl.XslTransform
_XSLTDocument.Load(xsltFileSpec,新的Xml.XmlUrlResolver)
否则抛出新的IO.FileNotFoundException(String.Format(&No; XLS
转换文档位于:{0}。),xsltFileSpec))
结束子

看来(对我来说)XSLTransform类没有被收集或者没有释放它占用的内存。我已经为持有这种方法的类提供了IDosposable
接口(虽然,我不明白为什么需要它,但我试图解决这个问题)。我确保
完成时,此类运行的线程确实处于停止状态。我已经筋疲力尽了,这里的任何帮助都会受到赞赏。

底线:为什么XSLTransform类的Load方法占用了这么多的内存,以及如何我发布了吗?

谢谢。

Malcolm Klotz
Hello,

I have created a Windows Service application in VB.Net 2005. The service is
pretty basic, it uses the System.Timers.Timer class to poll a database that
checks for jobs to perform. Upon finding a job, the
System.Timers.ElapsedEventHandler creates a new thread to execute the job.

The job is pretty basic, it uses and xml document and applies it to an XSLT
document using the XSLTransform class.

After this services runs a job the memory doubles, and keeps on doubling
until it finally crashes on memory. When I profiled this application, I
noticed the the Byte[] class was holding the most memory, and was surviving
all subsequent garbage collections. I pinned the Byte[] to the following
method:

Private _XSLTDocument As Xml.Xsl.XslTransform

Private Sub InitializeTemplate(ByVal aXSLTLocation As String)

Dim xsltFileSpec As String

If IO.File.Exists(aXSLTLocation) Then
_XSLTDocument = New Xml.Xsl.XslTransform
_XSLTDocument.Load(xsltFileSpec, New Xml.XmlUrlResolver)
Else
Throw New IO.FileNotFoundException(String.Format("No XLS
Transform document was found at: {0}.", xsltFileSpec))
End If

End Sub

It appears (to me) that the XSLTransform class is not being collected or is
not releasing the memory it occupies. I have impliemented the IDosposable
interface for the class that holds this method (although, I do not see why
it was needed, but I was trying to fix the problem). I have made sure that
the thread the this class runs on is indeed at a stopped state when
completed. I have exhausted my potentional, any help here would be
appreciated.

Bottom line: Why is the the Load method on the class XSLTransform taking up
so much memory, and how do I release it?

Thanks.

Malcolm Klotz



这就是我的想法( re。垃圾收集),看起来好像我粘贴了我的折旧代码,我使用的是XslCompiledTransform类,但是我还是看到了这个行为。你有什么特别的东西需要用它来清理吗?


谢谢。


Malcolm。


" G?ran Andersson" <顾*** @ guffa.com>在消息中写道

新闻:OT ************** @ TK2MSFTNGP03.phx.gbl ...
That is what I thought (re. garbage collection), it also seems as if I
pasted my depreciated code, I am using the XslCompiledTransform class, but I
still see this behaviour. Is there something special you have to do to a
thread to have it cleaned properly?

Thanks.

Malcolm.

"G?ran Andersson" <gu***@guffa.com> wrote in message
news:OT**************@TK2MSFTNGP03.phx.gbl...
奇怪。 XslTransform类没有实现IDisposable,因此它应该只包含托管资源,因此应该能够被垃圾收集器处理。

XslTransform类在框架2.0中已经过时了。您应该使用
XslCompiledTransform类。

Malcolm Klotz写道:
Strange. The XslTransform class doesn''t implement IDisposable, so it
should only contain managed resources, and thus should be able to be
handled by the garbage collector.

The XslTransform class is obsolete in framework 2.0. You should use the
XslCompiledTransform class instead.

Malcolm Klotz wrote:
您好,

我已经创建了一个Windows服务应用程序VB.Net 2005.该服务非常基础,它使用System.Timers.Timer类来轮询数据库,以检查要执行的作业。找到工作后,
System.Timers.ElapsedEventHandler创建一个新线程来执行
工作。

这个工作非常基础,它使用和xml文档并应用它使用XSLTransform类的XSLT文档。

此服务运行后,内存会翻倍,并继续加倍,直到它最终崩溃在内存中。当我分析这个应用程序时,我注意到Byte []类占用的内存最多,并且在所有后续垃圾收集中幸存下来。我将Byte []固定到
以下方法:

Private _XSLTDocument As Xml.Xsl.XslTransform
私有Sub InitializeTemplate(ByVal aXSLTLocation As String)

Dim xsltFileSpec As String

如果IO.File.Exists(aXSLTLocation)那么_XSLTDocument = New Xml.Xsl.XslTransform
_XSLTDocument.Load(xsltFileSpec,新的Xml.XmlUrlResolver)
否则抛出新的IO.FileNotFoundException(String.Format(&No; XLS
转换文档位于:{0}。),xsltFileSpec))
结束Sub

对我来说,似乎没有收集XSLTransform类或
没有释放它占用的内存。我已经为拥有这种方法的类暗示了
IDosposable接口(虽然,我不明白为什么需要它,但我试图解决这个问题)。我已经确保这个类运行的线程在完成时确实处于停止状态。我已经筋疲力尽了,任何帮助
这里都会受到赞赏。

底线:为什么XSLTransform类上的Load方法占用了这么多内存,以及如何我发布了吗?

谢谢。

Malcolm Klotz
Hello,

I have created a Windows Service application in VB.Net 2005. The service
is pretty basic, it uses the System.Timers.Timer class to poll a database
that checks for jobs to perform. Upon finding a job, the
System.Timers.ElapsedEventHandler creates a new thread to execute the
job.

The job is pretty basic, it uses and xml document and applies it to an
XSLT document using the XSLTransform class.

After this services runs a job the memory doubles, and keeps on doubling
until it finally crashes on memory. When I profiled this application, I
noticed the the Byte[] class was holding the most memory, and was
surviving all subsequent garbage collections. I pinned the Byte[] to the
following method:

Private _XSLTDocument As Xml.Xsl.XslTransform

Private Sub InitializeTemplate(ByVal aXSLTLocation As String)

Dim xsltFileSpec As String

If IO.File.Exists(aXSLTLocation) Then
_XSLTDocument = New Xml.Xsl.XslTransform
_XSLTDocument.Load(xsltFileSpec, New Xml.XmlUrlResolver)
Else
Throw New IO.FileNotFoundException(String.Format("No XLS
Transform document was found at: {0}.", xsltFileSpec))
End If

End Sub

It appears (to me) that the XSLTransform class is not being collected or
is not releasing the memory it occupies. I have impliemented the
IDosposable interface for the class that holds this method (although, I
do not see why it was needed, but I was trying to fix the problem). I
have made sure that the thread the this class runs on is indeed at a
stopped state when completed. I have exhausted my potentional, any help
here would be appreciated.

Bottom line: Why is the the Load method on the class XSLTransform taking
up so much memory, and how do I release it?

Thanks.

Malcolm Klotz



Hi Malcolm ,


你需要设置让GC清理内存没什么特别的。

GC唯一检查一个对象是否应该是最终确定是

对象引用。如果没有对象引用,它将被GCed。


请检查您的代码,如果您持有对该对象的引用

因此无法处理。


Kevin Yu

Microsoft在线社区支持


===== ============================================= ===== =====================

===================== =====

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ============================== ==================== ======

==========================


(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi Malcolm,

There is nothing special that you need to set to have GC clean the memory.
The only thing that GC checks to see if an object should be finalized is
object reference. If there is no object reference on it, it will be GCed.

Please check your code, if you''re holding some reference to that object
which makes it impossible to dispose.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)


这篇关于内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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