Select to view content in your preferred language

IFeatureCursor.NextFeature Leaks Memory (ArcGIS 9.2, VBA)

2758
9
06-17-2010 11:56 PM
ManuelF_
New Contributor
I have this function that gets called many times in a loop:

Private Function FindParcelOfObject(feat As IFeature) As IFeature
    Static fcursor As IFeatureCursor
    Set gSF.Geometry = feat.Shape 'gSF is ISpatialFilter declared at module level
    gSF.SpatialRel = esriSpatialRelWithin
    Set fcursor = gParcels.Search(gSF, True) 'gParcels is IFeatureClass declared at module level
    Set FindParcelOfObject = fcursor.NextFeature 'memory leak
    Set fcursor = Nothing
End Function

The line with NextFeature increases memory usage by about 6K each time it gets called. As the function is called many times, it exhausts memory very quickly. Is there something I do wrong here? Thank you.
0 Kudos
9 Replies
DuncanHornby
MVP Notable Contributor
"jmr1973",

Rather than have your SpatialFilter (gSF) declared globally at module level try creating it and destroying it within the procedure itself?

Duncan
0 Kudos
ManuelF_
New Contributor
"jmr1973",

Rather than have your SpatialFilter (gSF) declared globally at module level try creating it and destroying it within the procedure itself?

Duncan


Hi Duncan,

Unfortunately, this does not solve my problem. NextFeature is still grabbing a piece of memory with each execution.

Regards,
0 Kudos
AlexanderGray
Regular Contributor II
Have you tried setting the feature to nothing after you are done with it?
0 Kudos
DuncanHornby
MVP Notable Contributor
The only other thing I can tell from your code is the use of the Static keyword for declaring your featurecursor. I've never used Static (mainly out of ignorance in what it does!) I would have used Dim and have never come across the issues you are having, so try swapping that?

Duncan
0 Kudos
ManuelF_
New Contributor
The only other thing I can tell from your code is the use of the Static keyword for declaring your featurecursor. I've never used Static (mainly out of ignorance in what it does!) I would have used Dim and have never come across the issues you are having, so try swapping that?

Duncan


Static is there mainly so I don't have to declare a variable at module level as I already have too much of them. Since this function gets called about 10000 times i thought it would be more efficient to declare it like that than use Dim which would allocate memory each time it gets called. Anyway, I tried using Dim, same thing happens.
0 Kudos
ManuelF_
New Contributor
Have you tried setting the feature to nothing after you are done with it?


Alexander, I'll have to get back to you Monday as I don't have access to ArcGIS at home... thanks
0 Kudos
ManuelF_
New Contributor
Hi Alexander,

I set feature to Nothing and it still does not return memory to system... 😞 Any other ideas?
0 Kudos
JanDuske
New Contributor
Try to call
gParcels.Search(gSF, False) (not-recycling cursor) instead. The ESRI documentation says that it's forbidden to keep a reference to a row retrieved from a recycling cursor (can't say where I've read this, but I did...). The recycling cursor might even be responsible for the memory leak, since it does not release all its ressources as the non-recycling cursor does.
0 Kudos
AnilDhiman
New Contributor
Did you ever find solution to this,, I am also facing the such errors.
0 Kudos