Select to view content in your preferred language

Do geoprocessing tools leak handles (C#)?

654
5
11-30-2010 09:41 PM
MonikaThül
New Contributor
Dear list,

I've got a problem with a geoprocessing tool I implemented (C#).
It's using lots of ESRI's geoprocessing tools (mostly SingleOutputMapAlgebra). During the tool's execution the count of windows handles in use is rising and rising. Even (hours) after the tool has finished the handles are not freed.
I do not display result data in the map. So I see no reason for ArcMap to keep the handles. Saving the mxd document, clearing the results list of the current session don't help either.

Has anybody made the same observation?
Is there a way to force ArcMap to release unused handles?

Any hints will be appreciated

Thanks Monika
0 Kudos
5 Replies
AlexanderGray
Regular Contributor II
I am assuming you are creating a geoprocessor object in your C# code.  Do you dispose of this object using the arcobjects comreleaser or using the .net release com object method after you are done?  If not I suggest you do, it may help free the memory and/or handles.
Cheers
0 Kudos
MonikaThül
New Contributor
Dear Alexander,

since SingleOutputMapAlgebra is not an instance of ComObject I do not use the comreleaser (neither arcobjects nor .NET).

Or do I miss anything about the concept of COM objects?

Regards
Monika
0 Kudos
KenBuja
MVP Esteemed Contributor
In my 9.x projects using the Geoprocessor, I would use the ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject at the end of the geoprocessing routine. Here's an example (in VB.NET). However, I'm not sure what to use in ArcGIS 10

  Friend Sub DeleteDataset(ByVal InputName As Object)

    Dim DSDelete As New ESRI.ArcGIS.DataManagementTools.Delete
    Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult

    Try
      DSDelete.in_data = InputName

      Result = RunTool(DSDelete, Nothing)
      If Result Is Nothing Then System.Windows.Forms.MessageBox.Show("Unable to delete dataset '" & InputName & "'", "Unable to delete", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation)

    Catch ex As Exception
      ExceptionMessage(ex, "Delete Dataset")
    Finally
      ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(DSDelete)
    End Try

  End Sub
0 Kudos
AlexanderGray
Regular Contributor II
To my knowledge everything in ArcGIS that is exposed through an API is a COM object.  Even the objects in python are com objects underneath.  Same for the .NET and Java API (I haven't done much with the C++ API.)  Ken's code is good, I like to write it a little different with a using block (you can do the same in C#) and then I handle the exceptions at the highest level possible:


 
Friend Sub DeleteDataset(ByVal InputName As Object)


    Using releaser as new ComReleaser

      Dim DSDelete As New ESRI.ArcGIS.DataManagementTools.Delete
      releaser.ManageLifeTime(DSDelete)
      Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult
      DSDelete.in_data = InputName

      Result = RunTool(DSDelete, Nothing)
      If Result Is Nothing Then System.Windows.Forms.MessageBox.Show("Unable to delete dataset '" & InputName & "'", "Unable to delete", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation)

    End Using

  End Sub
0 Kudos
MonikaThül
New Contributor
thanks for your answers Ken and Alexander.
I followed your proposition using the 'using' statement.
Unfortunately to no avail. Handles are still counting up during execution.

So I'm still looking for a solution.

Regards Monika
0 Kudos