ArcObjects – Is It Permissible to Update Features After Feature Cursor Release?

arcobjectsc

In ArcObjects, is it permissible to modify and update a feature after the feature cursor (which was used to retrieve the feature) has been released?

That is, do features in any way retain a link to the cursor through which they were retrieved?

// retrieve a feature through a recycling feature cursor:
IFeatureClass featureClass = …;
IFeatureCursor featureCursor = featureClass.Search(nothing, true);
IFeature feature = featureCursor.NextFeature();

// release the feature cursor:
Marshal.FinalReleaseComObject(featureCursor);

// QUESTION: can the feature still be modified and updated?
feature.Value(…) = …;
feature.Store();
  • I'm programming against ArcGIS versions 9.3 and 10.
  • Does it possibly make a difference whether the cursor is recycling or non-recycling?

P.S.: I have tried this under both ArcGIS versions 9.3 and 10, and it seems to work fine; however, that doesn't mean that this will always work, nor that it should be done. I haven't found any hints about this issue in ESRI's online API documentation.

Best Answer

The key thing is whether the cursor is recycling or non-recycling.

Recycling cursors hand over the same instance for every feature, with different values on every iteration. I.e., they recycle the same instance. This is done for performance gains since less objects are instantiated. This also means you generally cannot keep the reference to your geodatabase objects retrieved with recycling cursors. As such, recycling cursors are not suitable if you do subsequent updates of the features.

Non-recycling cursors, on the other hand, instantiate separate instance for every feature they return. You can keep references to your objects within an edit session and perform updates on them via calling Store.

In your particlar code snippet, there is no difference since you are only retrieving a single feature. If you retrieved two and kept reference to each one of them, both references would point to the same object (the last one retrieved).

Definitely see the discussion at the bottom of IFeatureClass.Search. I also recommend you check out the Geodatabase library overview.


Update, as commented below: Feature instances do not reference the cursor used to retrieve them, so they are not in any way tied to it. So yes, you can refer to a feature if the cursor doesn't exist anymore, but (if you ignore the specific scenario with only one feature being fetched) it obviously only makes sense for non-recycling cursors.

Related Question