Garbage Collection Revit Documents

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I am currently writing a C# add-in that goes through a collection of Revit Projects and runs some file tests against them. My add-in runs reasonably fast and well, and I am able to properly get the data that I want out of the Revit Projects.
My problem lies in the way I am suspecting how Garbage Collection works using the Revit API. I have personally never done any memory management in programming other projects separate from Revit, so I may be speaking out of ignorance. The way my add-in works is that it opens the Revit project in the background (detaching it if its a central copy), runs the tests against it, then closes the project without saving by using the Document.Close(false) method (false meaning do not save the document). After my Revit add-in has run through all of the files, I find that Revit's memory usage has ballooned up by quite a bit (For example, before running the add-in Revit was only using ~600MB of memory, but after the Add-In has run, Revit reports that it is using ~2.5GB to sometimes over 5GB, but this is dependant on the number of projects I am running the tests against.)
What I have tried so far:
- Using the Document.Dispose() method after closing the file, but this doesn't seem to help too much.
- Explicitly calling GC.Collect(), but this doesn't free up memory either and just increases computation times instead.
I have read online that the inherent Garbage Collector in .NET only takes care of native library objects, but does not know what to do with un-managed resources created by third-party libraries such as Revit API objects. Would this mean that I would have to implement my own IDisposable class and methods? Would there be some sort of external library that could be used to manage memory better?
Thanks for any advice or recommendations.