473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Memory Leaks

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
7 1670
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
0
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have...
4
by: Morten Aune Lyrstad | last post by:
Ok, now I'm officially confused. I have a large project going, which uses a win32 ui library I am developing myself. And I'm getting weird memory leaks. I don't know if I can explain what is going...
2
by: Generic Usenet Account | last post by:
I have been using STL for a long time now, without any problems. Recently we generated a purification report on our software using Rational Purify, and we found some memory leaks. My colleague...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
4
by: ali.jan | last post by:
Hi, It is trivial to load an assembly in a new Application Domain. Is there any way of loading an assembly in a new process? I tried using the Process class like this: Process p = new...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
16
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.