Wednesday, December 09, 2009

XslCompiledTransform memory leak and diskspace usage

Recently we (me and my boss) discovered that Xslt files containing blocks will leak memory every time the stylesheet is getting compiled with XslCompiledTransform class from .NET 2.0 framework. Transforming xml against the compiled stylesheet will execute fine without memory leaks.

In our batch oriented service, we constantly loaded the stylesheet into a XslCompiledTransform object, compiled it and then transformed the data against it. Eating up memory rapidly.

So far the only resolution to this problem is to cache the XslCompiledTransform instance into a Dictionary class and re-use the instance.

We also noticed that blocks with C# or VisualBasic code will generate "temp" dll's in the users tempfolder containing the C# from the msxml:script block. Unfortunately these files are not cleaned up :)

The resolution to these temp dll, is simple. Don't allow msxml:script blocks, if needed one should create your own dll and create an instance of it before transform() and pass it on as an object-argument.

Regards,

Edwin

Monday, September 25, 2006

XPathNavigator missing SetAttribute

I have been using XPathNavigator for several weeks now. Early on I found out that it's a very usefull class. Microsoft did made GetAttribute and CreateAttribute. So where is SetAttribute?

The following function combines the two existing methods to support the SetAttribute.


void SetAttribute(
System.Xml.XPath.XPathNavigator navigator,
String prefix, String localName,
String namespaceURI,
String value)
{
if (navigator.CanEdit == true)
{
// Check if given localName exist
if (navigator.MoveToAttribute(localName, namespaceURI))
{
// Exist, so set current attribute with new value.
navigator.SetValue(value);
// Move navigator back to beginning of node
navigator.MoveToParent();
}
else
// Does not exist, create the new attribute
navigator.CreateAttribute(prefix, localName, namespaceURI, value);
}
}


Happy coding,

Edwin

Saturday, September 23, 2006

First blog msg

This is my first attempt to really start being a blogger.