Memory Leaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Malcolm Klotz

    #1

    Memory Leaks

    Hello,

    I have created a Windows Service application in VB.Net 2005. The service is
    pretty basic, it uses the System.Timers.T imer class to poll a database that
    checks for jobs to perform. Upon finding a job, the
    System.Timers.E lapsedEventHand ler 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.XslTran sform

    Private Sub InitializeTempl ate(ByVal aXSLTLocation As String)

    Dim xsltFileSpec As String

    If IO.File.Exists( aXSLTLocation) Then
    _XSLTDocument = New Xml.Xsl.XslTran sform
    _XSLTDocument.L oad(xsltFileSpe c, New Xml.XmlUrlResol ver)
    Else
    Throw New IO.FileNotFound Exception(Strin g.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




  • Göran Andersson

    #2
    Re: Memory Leaks

    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
    XslCompiledTran sform class instead.

    Malcolm Klotz wrote:[color=blue]
    > Hello,
    >
    > I have created a Windows Service application in VB.Net 2005. The service is
    > pretty basic, it uses the System.Timers.T imer class to poll a database that
    > checks for jobs to perform. Upon finding a job, the
    > System.Timers.E lapsedEventHand ler 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.XslTran sform
    >
    > Private Sub InitializeTempl ate(ByVal aXSLTLocation As String)
    >
    > Dim xsltFileSpec As String
    >
    > If IO.File.Exists( aXSLTLocation) Then
    > _XSLTDocument = New Xml.Xsl.XslTran sform
    > _XSLTDocument.L oad(xsltFileSpe c, New Xml.XmlUrlResol ver)
    > Else
    > Throw New IO.FileNotFound Exception(Strin g.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
    >[/color]

    Comment

    • Malcolm Klotz

      #3
      Re: Memory Leaks

      That is what I thought (re. garbage collection), it also seems as if I
      pasted my depreciated code, I am using the XslCompiledTran sform 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" <guffa@guffa.co m> wrote in message
      news:OT1zO4fkGH A.4304@TK2MSFTN GP03.phx.gbl...[color=blue]
      > 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
      > XslCompiledTran sform class instead.
      >
      > Malcolm Klotz wrote:[color=green]
      >> Hello,
      >>
      >> I have created a Windows Service application in VB.Net 2005. The service
      >> is pretty basic, it uses the System.Timers.T imer class to poll a database
      >> that checks for jobs to perform. Upon finding a job, the
      >> System.Timers.E lapsedEventHand ler 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.XslTran sform
      >>
      >> Private Sub InitializeTempl ate(ByVal aXSLTLocation As String)
      >>
      >> Dim xsltFileSpec As String
      >>
      >> If IO.File.Exists( aXSLTLocation) Then
      >> _XSLTDocument = New Xml.Xsl.XslTran sform
      >> _XSLTDocument.L oad(xsltFileSpe c, New Xml.XmlUrlResol ver)
      >> Else
      >> Throw New IO.FileNotFound Exception(Strin g.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
      >>[/color][/color]


      Comment

      • Kevin Yu [MSFT]

        #4
        Re: Memory Leaks

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

        Comment

        • Malcolm Klotz

          #5
          Re: Memory Leaks

          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-kevy@online.mic rosoft.com> wrote in message
          news:mJfjhhBlGH A.5700@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
          > 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.)
          >[/color]


          Comment

          • Kevin Yu [MSFT]

            #6
            Re: Memory Leaks

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

            Comment

            • Malcolm Klotz

              #7
              Re: Memory Leaks

              Kevin,

              I found the problem, thought it might be of interest to you and the group.
              I was using the class XSLCompiledTran sformation, 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.XslComp iledTransform(T rue), 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-kevy@online.mic rosoft.com> wrote in message
              news:ojh2abQlGH A.4864@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
              > 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.)
              >[/color]


              Comment

              • Kevin Yu [MSFT]

                #8
                Re: Memory Leaks

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

                Comment

                Working...