Word中的内存泄漏:HeaderFooter保留在内存中 [英] Memory Leak in Word: HeaderFooter remains in memory

查看:183
本文介绍了Word中的内存泄漏:HeaderFooter保留在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我们在Word加载项中使用了一些基于计时器的功能,并且在使用HeaderFooter对象时检测到内存泄漏。我们像这样访问对象:


(为简化而删除了COM)

  Word。 章节   wdSectionCollection  =  wdDocument.Sections; 
Word。
Section   wdFirstSection  =  wdSectionCollection [1];
Word。
HeadersFooters   wdHeaderFooterCollection  =  wdFirstSection.Headers;
Word。
HeaderFooter   wdHeaderFooter  =  wdHeaderFooterCollection [Microsoft.Office.Interop.Word。 WdHeaderFooterIndex 。wdHeaderFooterPrimary];

对于计时器事件的每个滴答,所有COM对象都在我们的加载项中发布。但是当使用HeaderFooter(几天后内存不足)时,内存会随着时间的推移而增长。如果我们删除HeaderFooter,则内存保持在预期的水平。


我们没有找到有关此案例的任何有用信息。使用HeaderFooter导致内存泄漏的原因是什么?


最好的问候


Christian

解决方案

Hi Christian,


我使用下面的代码进行了测试,似乎我可以重现你的问题,即没有释放HeaderFooter对象。但我在一个不合理的循环中用它来测试。你运行这段代码多少次?根据您的描述,几天后
内存不足,您运行文档多长时间了?在我的选项中,关闭文档后,将释放所有相关对象。你的意思是你一直保持文件开放吗?如果您可以分享关于您的要求的更多信息
将会有所帮助,然后我们可以尝试检查是否有任何解决方法。


最诚挚的问候,


Edward


Hello,

we use some timer based functionality in our Word Add-In and we detected a memory-leak when using the HeaderFooter object. We access the object like this:

(COM releasing removed for simplification)

Word.Sections wdSectionCollection = wdDocument.Sections; 
Word.
Section wdFirstSection = wdSectionCollection[1];
Word.
HeadersFooters wdHeaderFooterCollection = wdFirstSection.Headers;
Word.
HeaderFooter wdHeaderFooter = wdHeaderFooterCollection[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];

All COM-Objects are released in our Add-In for every tick of the timer event. But the memory grows over time when using HeaderFooter (out of memory after some days). If we remove the HeaderFooter the memory stays on an expected level.

We didn’t found any useful information about this case. What causes the memory leak with HeaderFooter?

Best Regards

Christian

解决方案

Hi Christian,

I made a test with below code, and it seems I could reproduce your issue that HeaderFooter object was not released. But I used it in an unreasonable loop to test. How many times you run this code? Based on your description, out of memory after some days, how long did you run your document? In my option, after closing the document, all of the related object will be released. Do you mean you keep document open all the time? It would be helpful if you could share us more information about your requirement, and then we could try to check whether there is any workaround.

Best Regards,

Edward


这篇关于Word中的内存泄漏:HeaderFooter保留在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆