Well Byref had no effect as I expected, save one, I used half as much memory from 11gb down to 5gb. With the file open and doing nothing in AutoCAD I started at 0.7GB, so talk about your bloat. There is one thing I'd like to investigate. The debugger keeps poping up this message:
ContextSwitchDeadlock was detected Message: The CLR has been unable to transition from COM context 0x477358 to COM context 0x476d90 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
I know little to nothing of multi-threaded documents, and weather or not I have any control over such things when working with AutoCAD .Net API. So this may be a white unicorn chase.
First of all, you should read my posts on AutoCAD Performance, it starts off slow but gets to the points you need to read about http://adndevblog.typepad.com/autocad/2012/07/the-
For the code you have listed, you should not mutiply call StartTransaction as it is really inefficient. You should change your code to either pass the currently started Transaction, or change to StartOpenCloseTransaction.
Finally, you should read this post about calling Dispose() http://adndevblog.typepad.com/autocad/2012/07/forc