By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,255 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,255 IT Pros & Developers. It's quick & easy.

Memory Leaks

P: n/a
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


Jun 16 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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:
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

Jun 17 '06 #2

P: n/a
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...
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:
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

Jun 19 '06 #3

P: n/a
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.)

Jun 20 '06 #4

P: n/a
Kevin,

Your advice makes sense, and what I believed was the problem. But, I am
setting the object to nothing at the end of the method.
Moreover, the thread that this object was created on has stopped, why would
the GC still see it as being referenced?
What else can I do to profile the problem?

Thanks.

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:mJ**************@TK2MSFTNGXA01.phx.gbl...
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.)

Jun 20 '06 #5

P: n/a
Hi Malcolm,

The object created on one thread can be referenced by object on another
thread. Also the thread stops, the reference is still there and the object
will not be finalized by GC.

There are some tools that can check what is referencing the object, like
WinDbg. You can try to post in the windbg newsgroups to see how to
troubleshoot on this issue.

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.)

Jun 21 '06 #6

P: n/a
Kevin,

I found the problem, thought it might be of interest to you and the group.
I was using the class XSLCompiledTransformation, and I had narrowed down the
leak to this class (actually several layers down, but this was the start of
the call), it seemed as if this instance was holding onto large Byte Arrays.
I changed the way I instantiated the class,
initially I had: New Xml.Xsl.XslCompiledTransform(True), however, when you
change it to false, the leak disappears. I had set it to true in development
to get detailed error messages with the XSL document I was using.

Not sure if this behaviour is by design, or whether there is a bug with
setting that flag to true.

(PS: I used ANTS profiler to help me out, pretty easy to use)

Thanks for you help.

Malcolm


"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:oj**************@TK2MSFTNGXA01.phx.gbl...
Hi Malcolm,

The object created on one thread can be referenced by object on another
thread. Also the thread stops, the reference is still there and the object
will not be finalized by GC.

There are some tools that can check what is referencing the object, like
WinDbg. You can try to post in the windbg newsgroups to see how to
troubleshoot on this issue.

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.)

Jun 23 '06 #7

P: n/a
Hi Malcolm,

I did some research, but didn't find any information related to this issue.
Anyway, it's good to known that you have had a workaround. Thanks for your
feedback. I'll forward this to product team through an appropriate channel.

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.)

Jun 26 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.