tags:

views:

47

answers:

1

Common story: I develop an ArcMap extension using C#. Most problems can be solved by using all kinds of geoprocessing tools from ArcToolbox. What is generally more advisable:

  1. Creating a new geoprocessor object for each tool?
  2. Re-using one single geoprocessor object?

When 1) is recommended, do I have to release the com object after a single tool has been executed? Whats about calling GC.Collect()?

When 2) is recommended, is it a good method to instantiate it once and reuse it over and over again, for example using the singleton pattern?

My personal experience is that using the second method, I run into serious memory access violations while debugging my code.

A: 

I'd probably choose to create a new object for each. If you use multiple threads, it's neccessary anyway to avoid need for synchronization.

And yes, you need to release each com object as soon as possible, but don't call GC.Collect().

See here: http://msdn.microsoft.com/en-us/library/ff647812.aspx

František Žiačik