Home All Groups Group Topic Archive Search About
Author
16 Jun 2006 8:02 PM
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

Author
17 Jun 2006 11:06 AM
Göran_Andersson
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:
Show quoteHide quote
> 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
>
Author
19 Jun 2006 1:16 PM
Malcolm Klotz
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.

Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:OT1zO4fkGHA.4304@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
>>
Author
20 Jun 2006 3:19 AM
Kevin Yu [MSFT]
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.)
Author
20 Jun 2006 10:10 PM
Malcolm Klotz
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.

Show quoteHide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:mJfjhhBlGHA.5700@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.)
>
Author
21 Jun 2006 7:46 AM
Kevin Yu [MSFT]
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.)
Author
23 Jun 2006 1:33 PM
Malcolm Klotz
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




Show quoteHide quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:ojh2abQlGHA.4864@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.)
>
Author
26 Jun 2006 8:02 AM
Kevin Yu [MSFT]
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.)