Geoprocessing tool leaking memory

3272
7
04-13-2011 05:08 AM
Md__ImranHossain
New Contributor
I am using the point solar radiation geoprocessing tool in a loop of around 100000 times. I have noticed that the virtual memory increases tremendously after each loop. Thus after a certain time the program crashes when the virtual memory gets its maximum limit. 

The problem seems that the geoprocessing tool object is unable to release the resources once it goes out of scope. Please note that I have tried almost all possible options to destroy the object (geoprocessing tool) once it goes out of scope. For example, I have tried AOUninitialize.Shutdown()method, ComReleaser.ReleaseCOMObject () method, Marshal.ReleaseComObject() method, Garbage collector etc. but none of those could solve the problem.

Besides, I have tried to execute the geoprocessing tool separately with managed and unmanaged assembly to observe any noticeable changes in the virtual memory consumption. But, unfortunately nothing good happened.

Finally, I have tried to run the code specific for executing the point solar radiation tool in a separate subroutine so that in each loop the program jump in to that separate sub, execute the geoprocessing tool and exit the sub. The idea was, with the exit of sub, the system should release all the resources and allocated memory. But again it failed.

now my queries are:

1. Is there any other way to solve this problem
2. Is this a serious bug still alive in the arcobjects
3. If it is a bug then how long the user have to wait for a solution.
0 Kudos
7 Replies
StefanOffermann
Occasional Contributor II
Did you try to release the Geoprocessor object and call garbage collection afterwards? This should be done after calling a single geoprocessing tool to avoid strange affects regarding memory issues.
0 Kudos
Md__ImranHossain
New Contributor
Hello Stefan!

Yes, I tried. For example:

comReleaser.ReleaseCOMObject(GP)
GP = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()

But it did not work. Any other idea??

Thanks,

Imran
0 Kudos
KenBuja
MVP Esteemed Contributor
Have you tried using the ESRI.ArcGIS.ADF.ComReleaser? Here's an example of one of my geoprocessing subroutines.

    Friend Sub DeleteObject(ByVal pInObject As Object)

        Dim Delete As New ESRI.ArcGIS.DataManagementTools.Delete
        Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Try
            Using releaser As New ESRI.ArcGIS.ADF.ComReleaser
                releaser.ManageLifetime(Delete)
                Delete.in_data = pInObject

                Result = RunTool(Delete, Nothing)

                If Result Is Nothing Then
                    System.Windows.Forms.MessageBox.Show("Could not delete object")
                End If
            End Using

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Delete error")
        End Try

    End Sub

    Private Sub ReturnMessages(ByVal pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Title As String)

        Dim ErrorMessage As String

        If pResult.MessageCount > 0 Then
            For Count As Integer = 0 To pResult.MessageCount - 1
                ErrorMessage += pResult.GetMessage(Count)
            Next
        End If

        System.Windows.Forms.MessageBox.Show(ErrorMessage, Title)

    End Sub

    Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

        Try
            Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
            If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then ReturnMessages(Result, "Geoprocessing Error")
            GP.ClearMessages()
        Catch ex As Exception
            ReturnMessages(Result, "Fail")
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")
        End Try

        Return Result

    End Function
0 Kudos
Md__ImranHossain
New Contributor
Hello kenbuja!!

Thanks for your attention!
I have applied your geoprocessing sub but still no luck, sorry to say.
I am using point solar radiation tool and perhaps this particular geoprocessing tool has some bugs (Just a wild guess). I would highly appreciate if you have any other idea.

I would also like to take attention from ESRI guys in this regards.

Thanks,

Imran
0 Kudos
JeffreySwain
Esri Regular Contributor
Can you indicate how large of an area you are processing?  Generally speaking the tool is not recommended if the size of the area being analyzed is larger that one degree of latitude.  In the help, there are other recommendations including the sky size, coordinate system and output options.

In terms of the memory issue, the tool is very memory intensive and successive runs will create problems.  Have you considered using spawnV? Here are some forum posts that indicate some success with deleting the geoprocessor that way for intensive runs. 

There are also more tips here.
0 Kudos
Md__ImranHossain
New Contributor
Hello Jeff!

Thanks a lot for your attention!

Well, the area is only 50x50 meter means it is small enough to run the tool. The other parameters like sky size, coordinate system, zenith and azimuth division etc. were kept as default.

As regards using spawnV, please note that I am using VB.NET as the language and I have tried all possible options to destroy the GP once it goes out of scope. But it did not work.

Thanks,

Imran
0 Kudos
JohnHauck
Occasional Contributor II
What version are you using? If you are using ArcGIS 10.0 I'm curious to know if running the tool in the background would allow you to avoid this.
0 Kudos