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