Memory Leak in Word: HeaderFooter remains in memory RRS feed

  • Question

  • 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; 
    Section wdFirstSection = wdSectionCollection[1];
    HeadersFooters wdHeaderFooterCollection = wdFirstSection.Headers;
    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


    Friday, July 22, 2016 6:49 AM

All replies

  • 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,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 25, 2016 9:11 AM