You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XpsDocument.GetFixedDocumentSequence()内存泄漏问题求助

XPS文档处理中的内存泄漏与服务崩溃问题

我在执行以下代码时遇到了内存泄漏问题:

var fixedSequence = xpsDoc.GetFixedDocumentSequence(); 
if (fixedSequence == null) return;

我尝试了几种针对WPF内存泄漏的常见解决方案(包括调用UpdateLayout的方法),但都没能解决问题,最终导致Windows服务崩溃,抛出两种异常:

  • 内存不足异常(触发点在XpsDocument.GetFixedDocumentSequence())
  • System.Windows.Markup.XamlParseException

System.Windows.Markup.XamlParseException的详细堆栈信息:

Exception Info: System.ComponentModel.Win32Exception at MS.Win32.UnsafeNativeMethods.CreateWindowEx(Int32, System.String, System.String, Int32, Int32, Int32, Int32, Int32, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Object)
at MS.Win32.HwndWrapper..ctor(Int32, Int32, Int32, Int32, Int32, Int32, Int32, System.String, IntPtr, MS.Win32.HwndWrapperHook[])
at System.Windows.Media.MediaContextNotificationWindow..ctor(System.Windows.Media.MediaContext)
at System.Windows.Media.MediaContext..ctor(System.Windows.Threading.Dispatcher)
at System.Windows.Media.MediaContext.From(System.Windows.Threading.Dispatcher)
at System.Windows.Media.Visual.VerifyAPIReadWrite()
at System.Windows.Media.VisualCollection.Add(System.Windows.Media.Visual)
at System.Windows.Controls.UIElementCollection.AddInternal(System.Windows.UIElement)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(System.Object, System.Xaml.XamlType, System.Object, System.Xaml.XamlType)
Exception Info: System.Windows.Markup.XamlParseException at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, Boolean, System.Uri)
at System.Windows.Markup.XamlReader.Load(System.Xaml.XamlReader, System.Windows.Markup.ParserContext)
at System.Windows.Markup.XamlReader.Load(System.Xml.XmlReader, System.Windows.Markup.ParserContext, System.Windows.Markup.XamlParseMode)
at System.Windows.Markup.XamlReader.Load(System.IO.Stream, System.Windows.Markup.ParserContext)
at System.Windows.Xps.Packaging.XpsDocument.GetFixedDocumentSequence()
at Softdocs.Imaging.MultiPageStreamSplitter.b__1()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

内容的提问来源于stack exchange,提问作者Sudhakar Boyini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:33:08