CLR Garbage disposal
-
11 Nopember 2009 17:02
Hopefully this is sufficiently on topic here. I am modifying some legacy code, attempting to improve the garbage collection in a CLR function. Unfortunately, I have very little experience with the objects involved.
the code does an xsl transform. It creates a memory stream when it does the transform, and loads the memory stream into a new SqlXml object and outputs it. I want to explicitly dispose the memory stream, but when I do, I get the error:'Invalid attempt to call Read when the stream is closed.'
here is my code in its current state, although I've tried several variations:
public static SqlXml SqlXslTransform(SqlXml XmlData, SqlXml XslData) { // Load XSL transformation System.Xml.Xsl.XslCompiledTransform xform = new System.Xml.Xsl.XslCompiledTransform(); xform.Load(XslData.CreateReader()); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { xform.Transform(XmlData.CreateReader(), null, ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Return the transformed value SqlXml retSqlXml = new SqlXml(ms); return (retSqlXml);I've tried to figure out how I can declare the retSqlXml early, rather than create it inside the using{} block, but I don't see any sort of load() method. Is there a way to dispose of the memory stream and still output the SqlXml object, or do I have to leave the stream open? Is it creating a memory leak if I do? We are having memory pressure issues on the server caused by this function.
Any help appreciated.
Semua Balasan
-
03 Februari 2012 12:22
Hi,
Perhaps you had any luck with this one? I'm in the same situation. It seems that SqlXml is only a pointer to stream so if the stream is disposed, the SqlXml object is disposed also.
Thanks
-
26 Juli 2012 13:50
As I recall, I ended up re-writing the proc in T-SQL and have avoided using the CLR ever since. :)
-Tab Alleman
- Ditandai sebagai Jawaban oleh Tab Alleman 2 26 Juli 2012 13:51