Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Quick question, in Esri's area calculation sample of IGPFunction implementation they use IGPUtilities but they don't release the instance.

On the singletons page in SDK help they list GPUtilities as a singleton object. So shouldn't our instances of IGPUtilities be released? And also should we not use the Activator class to create the instance?

In a IGPFunction implemented class do people have any preference on creating a class instance of IGPUtilities (like in the Esri Area Calculator example) or create them in the methods when needed?

Thanks Rob

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Yes, ideally, you should use Activator to get a GPUtilities instance.

You do not need to release it, though. Once the class is instantiated, ArcObjects keep the single instance in memory. Any effort on your part to release it in .NET will only result in releasing its RCW (runtime callable wrapper), not the actual instance. Garbage collector will do that for you anyway and in this case there is no need for the RCW to be released in a timely manner, since the actual COM object will still live on until the thread which owns it terminates.

share|improve this answer
    
+1 Any thoughts on when IGpUtilities.ReleaseInternals should be called? –  Kirk Kuykendall Jan 29 '12 at 23:43
    
Oh, right, perhaps the OP meant ReleaseInternals() when he spoke about releasing IGPUtilities? –  Petr Krebs Jan 30 '12 at 8:53
1  
I'm not sure. A long time ago I had a geoprocessing issue that I ended up resolving by calling ReleaseInternals. I'm not sure why that fixed it. "Releases all internal objects used prior to releasing this GPUtilities object." ... But singletons shouldn't need releasing. GpUtilities sure smells like a God Object to me. –  Kirk Kuykendall Jan 30 '12 at 14:20
    
Well I actually meant both ReleaseInternals and the standard Marshal.ReleaseComObject. I started using ReleaseInternals but didn't seem to do anything, perhaps it clears the layers and temp data etc that are created in the GeoProcessor (e.g. MakeFeatureLayer etc.) Anyway Thanks Petr, answered my question. –  Rob Jan 31 '12 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.