Feb 11, 2013 at 5:51 PM
Edited Feb 11, 2013 at 5:58 PM
Thank you for quick answers!
Our Word add-in processing text very intensively. For example, it scans text for changes by constantly moving through sentences in text and comparing them with cached text representation. We actively getting ranges from document, often getting them from another
ranges with Next or Duplicate.
Something like this
Range x = GetSomehowFromDocument(_doc);
Range r = x.Next(WdUnits.wdSentence);
Range r2 = r.Duplicate;
And in some places it even works with text by char (with Next(WdUnits.wdCharacter).
So, if we call x.Dispose in Above example, it will release r and r2. Am I right? And while user is working with document we can't dispose and memory keep flooding.
I concluded that leaks can be caused by objects collected in lists and by unreleased COM-objects and did following:
- Removed COMObject.AddChildObject
- Removed Factory.AddObjectToList
- Added destructor
And it seems to work! Word process is no longer growing in memory even with infinite document scan (from separate thread, by the way).
Initialize error faded when I added sources from NetOffice to my solution and referenced project that I needed (instead of referencing compiled dlls). I can't understand why.
Am I missing something? What can be consequences of those changes?
I am understanding that I am losing Dispose this way, but I don't need it anymore - GC is doing all work for me.
Factory.AddObjectToList and _globalObjectList needed only for DisposeAllCOMProxies?
I think, that if everything ok it would be the useful option for the next release - as some switch (like you did with threads).