Resource Leak from XslCompiledTransform

W

W. Jordan

Hello there,

Are there anybody who is using the XslCompiledTransform that comes
with .net framework, which was said to be a replacement of the
XslTransform class?

I found that the class has some issues when the xsl file contains scripts.

The XslCompiledTransform uses the CodeDom to compile the scripts
within the xsl file into .net assembly and load them into the current
AppDomain. Some temporary files would be generated during the
compilation in the temp folder.

This behavior leads to two issues.

1, The memory consumption of the current AppDomain, i.e. the
working application keeps growing up if we compile more and more
xsl files that contain scripts. We have no way to identify the assembly
generated from the compiled scripts within the xsl files. Thus we can
not release the resources associated with the xsl files.

2, The temporary assembly files can not be removed while the
application is executing, since they are engaged by it. The TempFiles.Delete
method always fails within the application, consequently. And after
running the application for several times, the temp folder might be
piled up with the those temporary files.

Are there any approaches to solve these problems?
 
G

Guest

Sorry for the late answer. The issue #1 is common for both XslTransform and
XslCompiledTransfom. The only solutions are: a) using extension objects
instead of msxsl:script blocks; b) recycling the AppDomain from time to time.

For issue #2 let me cite the "Introducing XslCompiledTransform" article
available at
http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx:

Cleanup: TemporaryFiles Property

If a stylesheet contains script blocks, or it is compiled with the
enableDebug flag set to true, XslCompiledTransform may create some temporary
files in the %TEMP% folder. When the finalizer of a TempFileCollection object
(which keeps track of created temporary files), tries to remove all of them,
some files may be in use by the current AppDomain (*.DLL files) or by the
debugger (*.PDB files). Those files cannot be deleted until unloading the
AppDomain or detaching the debugger. If you frequently compile XSLT
stylesheets with script blocks, the %TEMP% folder may become overcrowded with
temporary files left undeleted. To ensure that all temporary files will be
removed, an advanced client may use the TemporaryFiles property to save paths
of temporary files for a further cleanup.
 
W

W. Jordan

Hello,

Thanks for your reply.
Sometimes the extension objects are not so convenient, but another AppDomain
seems to be an overkill. Anyway, these are the most common workarounds
nowadays.
To eliminate the temp files, I guess that managing another AppDomain would
be
a little easier to implement. Some other aproaches utilize database or log
files
to keep tracks of those temp files during the starts of the application,
which might
be somewhat awkward. The XslTransform class appears that it does not produce
any temp files, thus it might be a tad easier to manipulate, considering
those temp
files.
Thanks again for your answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top