English

Problem: Memory usage increases while iterating over rows/features in a cursor

Description

Memory usage increases while iterating over rows/features in a nonrecycling cursor when in an edit session.

Code:
pWorkspaceEdit.StartEditing True
Set pCursor = pTable.Search(Nothing, False)
Set pRow = pCursor.NextRow
Do Until pRow Is Nothing
'Memory is accumulated for each row
Set pRow = pCursor.NextRow
Loop
Set pCursor = Nothing 'Memory is freed

Cause

The cursor maintains a reference to each row that it has iterated over. It holds these objects in memory until the cursor is released, at which point the rows are released. Only then is memory deallocated for the rows that are no longer referenced by anything in the system.

Solution or Workaround

This issue can be avoided by:
- Using a nonrecycling cursor outside an edit session.
- Using a recycling cursor either outside or inside an edit session. The following code example demonstrates how to use a recycling cursor.

Code:
pWorkspaceEdit.StartEditing True
Set pCursor = pTable.Search(Nothing, True)
Set pRow = pCursor.NextRow
Do Until pRow Is Nothing
'The same row object is used over again.
'No additional memory is used.
Set pRow = pCursor.NextRow
Loop
Set pCursor = Nothing