2 featureclass searches, first always works and second always fails

652
3
01-09-2013 05:40 AM
GaryBushek
New Contributor III
I'm getting some errors trying to do a search on a feature class.  The first search always works but the second search seems to fail 80% of the time and its typically a crash on line "pFC4 = streetSegFC2.Search(pSF4, True)".  Im assuming it crashes instead of being caught because of an "out of memory" error.  I'm realeasing the first cursor the best I can in every way i know how to but it seems to still be holding onto the cursor in memory. Originally I was using the same featureclass to search from but I decided to create a separate instance of the featureclass and that didn't help.  I tried creating a completely separate workspace to create the second featureclass from which triggered a completely separate SDE stream/connection but it still fails.  Any ideas on what to do if the cursors or memory aren't being fully released?  The 2 searches below are virtually identical and hitting the same database featureclass.

Thanks, Gary

            pSF = New SpatialFilterClass()
            pcomReleaser.ManageLifetime(pSF)

            pSF.Geometry = pTopo.Buffer(bufTol)
            pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            pSF.WhereClause = "FULLSTNAME='MAIN ST'"

            Try

                pFC = streetSegFC.Search(pSF, True)
                pcomReleaser.ManageLifetime(pFC)

                pF = pFC.NextFeature

                If pF Is Nothing Then
                    Log.Log(LogLevel.DetailedInfo, "No streets found", _logFileName)
                    Return Nothing
                End If

            Catch ex As Exception
                Log.Log(LogLevel.Exception, ex.Message & vbCrLf & ex.StackTrace, _logFileName)
            Finally

                pcomReleaser.dispose()

                Common.Release(pFC)

                pFC = Nothing

            End Try

....
Some code
....

            pSF4 = New SpatialFilterClass()
            pcomReleaser.ManageLifetime(pSF4)

            pSF4.Geometry = pTopo2.Buffer(bufTol)
            pSF4.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            pSF4.WhereClause = "FULLSTNAME='MAIN ST'"

            Try

                pFC4 = streetSegFC2.Search(pSF4, True)
                pcomReleaser.ManageLifetime(pFC4)

                pF4 = pFC4.NextFeature

                If pF4 Is Nothing Then
                    Log.Log(LogLevel.DetailedInfo, "No streets found", _logFileName)
                    Return Nothing
                End If

            Catch ex As Exception
                Log.Log(LogLevel.Exception, ex.Message & vbCrLf & ex.StackTrace, _logFileName)
            Finally

                pcomReleaser.dispose()

                Common.Release(pFC4)

                pFC4 = Nothing

            End Try

0 Kudos
3 Replies
JasonPike
Occasional Contributor
I'm getting some errors trying to do a search on a feature class.  The first search always works but the second search seems to fail 80% of the time and its typically a crash on line "pFC4 = streetSegFC2.Search(pSF4, True)".  Im assuming it crashes instead of being caught because of an "out of memory" error.  I'm realeasing the first cursor the best I can in every way i know how to but it seems to still be holding onto the cursor in memory. Originally I was using the same featureclass to search from but I decided to create a separate instance of the featureclass and that didn't help.  I tried creating a completely separate workspace to create the second featureclass from which triggered a completely separate SDE stream/connection but it still fails.  Any ideas on what to do if the cursors or memory aren't being fully released?  The 2 searches below are virtually identical and hitting the same database featureclass.

Thanks, Gary

            pSF = New SpatialFilterClass()
            pcomReleaser.ManageLifetime(pSF)

            pSF.Geometry = pTopo.Buffer(bufTol)
            pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            pSF.WhereClause = "FULLSTNAME='MAIN ST'"

            Try

                pFC = streetSegFC.Search(pSF, True)
                pcomReleaser.ManageLifetime(pFC)

                pF = pFC.NextFeature

                If pF Is Nothing Then
                    Log.Log(LogLevel.DetailedInfo, "No streets found", _logFileName)
                    Return Nothing
                End If

            Catch ex As Exception
                Log.Log(LogLevel.Exception, ex.Message & vbCrLf & ex.StackTrace, _logFileName)
            Finally

                pcomReleaser.dispose()

                Common.Release(pFC)

                pFC = Nothing

            End Try

....
Some code
....

            pSF4 = New SpatialFilterClass()
            pcomReleaser.ManageLifetime(pSF4)

            pSF4.Geometry = pTopo2.Buffer(bufTol)
            pSF4.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            pSF4.WhereClause = "FULLSTNAME='MAIN ST'"

            Try

                pFC4 = streetSegFC2.Search(pSF4, True)
                pcomReleaser.ManageLifetime(pFC4)

                pF4 = pFC4.NextFeature

                If pF4 Is Nothing Then
                    Log.Log(LogLevel.DetailedInfo, "No streets found", _logFileName)
                    Return Nothing
                End If

            Catch ex As Exception
                Log.Log(LogLevel.Exception, ex.Message & vbCrLf & ex.StackTrace, _logFileName)
            Finally

                pcomReleaser.dispose()

                Common.Release(pFC4)

                pFC4 = Nothing

            End Try




Try putting the result of pTopo.Buffer(bufTol) into a variable before assigning it to pSF4.Geometry and releasing it using Marshal.ReleaseComObject.

If you'll post an example that compiles, runs, and reproduces the problem, I'll be happy to go through it more thoroughly.
0 Kudos
GaryBushek
New Contributor III
I'll give that a try.  We put a ticket in with ESRI and one suggestion we got was to retrieve the feature class from the map server object instead of the using IFeatureWorkspace.OpenFeatureClass().  We were hoping to get around changing the code too much because its a migration from 9.1 and a relatively large complex process.  thanks for the tip and i'll give an update as soon as I know either way.

Gary
0 Kudos
JasonPike
Occasional Contributor
I'll give that a try.  We put a ticket in with ESRI and one suggestion we got was to retrieve the feature class from the map server object instead of the using IFeatureWorkspace.OpenFeatureClass().  We were hoping to get around changing the code too much because its a migration from 9.1 and a relatively large complex process.  thanks for the tip and i'll give an update as soon as I know either way.

Gary


Great! Also, here is something else you can use to help analyze the problem (use UMDH to show stacks that are hanging around in memory): http://forums.arcgis.com/threads/75186-Memory-leak-with-FeatureClass-object?p=263735#post263735

Good luck. I'm very interested to hear what you find out.
0 Kudos