Tuesday, December 16, 2014

ArcObjects Recycled Cursors

If you are new to ArcObjects, you must have seen this Boolean parameter when you want to create a search cursor. This might be confusing for some new developers. I didn't know about it in the beginning so I used to insert a false there every time.

Actually this very Boolean parameter can really ruin your entire application and produce unexpected results if used in the wrong context.

What is Recycling?
Recycling is reusing the same memory location for creating features or rows.

When to use Recycling?
Recycling cursor is much more efficient than non-recycling one. It is great for populating lists and printing values in the screen.

Here are some cases you want to use Recycling in
  • Populating Features' attributes in a list
  • Saving certain primitive features attributes (like objectid) in a collection

When not to use Recycling?
When capturing the feature or its geometry (or any other non-primitive reference) , DO NOT use Recycling cursor. If you did you will simply get the same feature (probably the last one) in all your collection because it is using the same memory location.

Here are some cases you must not use Recycling in
  • Union the geometry of all features in a given cursor
  • Saving the feature geometry in the Grid Tag or collections
  • Comparing features

I even made you a video guys!

Hope that helped!