XslCompiledTransform.Transform 64 位内存问题

发布于 2024-11-16 05:50:16 字数 176 浏览 3 评论 0原文

我们的应用程序使用 XslCompiledTransform.Transform 函数。如果我们在 32 位模式下运行,该行为是正常的,但是在 64 位模式下运行时,内存消耗会跳得太高(并最终抛出内存不足异常)。相同的代码,相同的机器 - 一个可以工作,而另一个则不能......有人见过类似的问题并有解决方法吗?

谢谢,

Our application uses the XslCompiledTransform.Transform function. The behavior is normal if we run it in 32 bit mode, however when running under 64 bit mode, the memory consumption just jumps way too high (and eventually throws out of memory exception). Same code, same machine - one works while the other does not ....Has anyone seen a similar issue and have a workaround?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风吹雪碎 2024-11-23 05:50:16

它实际上是由于分配给线程的内存不足而导致的 OutOfMemoryExceptionStackOverflowException 吗?我问这个问题是因为我在运行 IIS 的 x64 Web 服务器上遇到了此类问题,如 默认情况下,它只为线程堆栈分配 256kb。我必须在线程中进行一些较大的转换(如 DocBook 到 XSL-FO)以这种方式为堆栈提供更多空间:

var stackedThread = new Thread(RunXsltWithMoreMemory, 2 * 1024 * 1024);
var threadParameters = ThreadXsltParameters {
    InputStream = inputStream;    // Source XML
    OutputStream = outputStream;  // Resultant XML
};
stackedThread.Start(threadParameters);
stackedThread.Join();

Is it actually an OutOfMemoryException or a StackOverflowException due to insufficient memory being allocated to the thread? I ask because I ran into this type of problem on an x64 web server running IIS, as it only allocates 256kb to a Thread's stack by default. I had to do some of the larger transforms (like DocBook to XSL-FO) in a Thread with more room for the stack in this fashion:

var stackedThread = new Thread(RunXsltWithMoreMemory, 2 * 1024 * 1024);
var threadParameters = ThreadXsltParameters {
    InputStream = inputStream;    // Source XML
    OutputStream = outputStream;  // Resultant XML
};
stackedThread.Start(threadParameters);
stackedThread.Join();
我的影子我的梦 2024-11-23 05:50:16

我最近遇到了这个问题,并通过使用 xsltc 命令行实用程序编译 XSLT 来解决它。

 xsltc someXsl.xsl /settings:DTD+,document+,script-

xsltc 命令行实用程序在 MSDN 上有记录:http://msdn.microsoft .com/en-us/library/bb399405.aspx

然后,一旦运行命令行实用程序,就会生成一个程序集,您可以在代码中使用它,如下所示:

 xmlTransform.Load(Assembly.Load(assemblyName).GetType(assemblyName));

它似乎还显着提高了转换性能。

I've recently run into this problem and have resolved it by compiling my XSLTs using the xsltc command-line utility.

 xsltc someXsl.xsl /settings:DTD+,document+,script-

The xsltc command-line utility is documented here on MSDN: http://msdn.microsoft.com/en-us/library/bb399405.aspx.

And then once you've run the command-line utility, an assembly is generated which you use in your code like this:

 xmlTransform.Load(Assembly.Load(assemblyName).GetType(assemblyName));

It also seems to have significantly increased performance of the transformations.

国粹 2024-11-23 05:50:16

虽然 XslCompiledTransform 在这一点上是古老的技术,可能不会被太多使用,但我最近在 .NET 4.5 中做了一些测试,似乎这个内存消耗错误已经得到修复。

我无法从 Microsoft 找到任何明确的指示(我似乎无法再访问旧的 Connect bug),但是使用相当复杂的 XSLT(几千行)和大量 xpath 表达式进行测试并没有显示任何异常.NET 4.5 中 64 位进程的内存使用情况。在 .NET 3.5 64 位中执行相同的 XSLT 会立即在 8 GB 计算机上跳转到 6.5 GB,并从那里继续增加。

我很好奇其他人是否仍然可以在 64 位 .NET 4.5 中使用 XslCompiledTransform 重现不良的内存使用行为,或者是否知道 Microsoft 与此问题相关的任何更新。

While XslCompiledTransform is ancient technology at this point and might not be used much, I've done some recent testing in .NET 4.5 and it seems like this memory consumption bug has been fixed.

I haven't been able to find any definitive indication from Microsoft (I can't seem to access the old Connect bug anymore), but testing with a fairly complex XSLT (several thousand lines) with plenty of xpath expressions does not show any abnormal memory usage in 64-bit processes in .NET 4.5. Executing this same XSLT in .NET 3.5 64-bit immediately jumps to 6.5 GB on an 8 GB machine and keeps going up from there.

I'm curious as to whether or not anyone else can still reproduce the bad memory usage behaviour with XslCompiledTransform in 64-bit .NET 4.5 or knows of any updates from Microsoft related this problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文