Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
Yes. It is fine. The recycling cursor answer below addresses your second question :) –  Ragi Yaser Burhum Oct 19 '11 at 23:46
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
Unfortunately, this does not answer my question. I was not asking whether you can still refer to a feature when the cursor has advanced to a subsequent feature; I was asking whether you can still refer to a feature if the cursor doesn't exist anymore. –  stakx Oct 16 '11 at 2:26
1  
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, but (if you ignore the specific scenario with only one feature being fetched) it obviously only makes sense for non-recycling cursors. –  Petr Krebs Oct 16 '11 at 11:31
add comment

As @petr-krebs mentioned, feature objects don't reference their cursors. However, the database state is connected to cursor handles, and the behavior of feature objects depends on the database state.

It was my understanding that while you have a handle to a database cursor, the database guarantees "consistency and isolation" in transactions (defined here, as described by @ragi-yaser-burhum (profile) in regard to ArcObjects performance here). So, if you release the handle before performing updates and lose these guarantees, it may be possible to put the database into an invalid state.

This could have a serious impact on operations within a busy ArcSDE environment. However, my experience is mostly with file geodatabases, where only one process may write to a table at a time. I use an extension method on (non-recycling) cursors to fetch all IFeatures in a List<> and release the cursor well before editing. I've never observed any inconsistent behavior from this.

I could use a bit more clarity on this topic myself.

share|improve this answer
    
That is some interesting insight into ArcGIS geodatabase internals. Is the features' dependence on database state documented somewhere? What your answer makes me wonder is, why is database state associated with cursor handles -- why not with transactions (via the ITransactions interface supported by some types of workspace)? –  stakx Oct 20 '11 at 19:59
    
This is all the documentation I've found: "Cursors should be scoped to a single edit operation. This means a new cursor should be instantiated and released for each operation. This is very important when editing rows returned by a cursor because the rows are tied to a specific state of the geodatabase." found here in the ArcObjects SDK –  Scott B Oct 24 '11 at 13:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.