Cursor and row classes as context managers

Idea created by niklas.norrthonesri-se-esridist Employee on Jan 30, 2011
    Implemented
    Score100
    I propose that the cursor and row classes get a new method close() that will return and unlock all resources the object in question has allocated. Furthermore in arcpy these classes should implement the python context manager protocol, so one could write code as:
     
    with arcpy.SearchCursor('some_feature_class') as cur:
        for row in cur:
            print row.getValue('some_field')
            row.close()

    Calling methods on closed objects should raise a descriptive exception, just like calling methods on a closed file would do.

    Today there is no way to ensure that allocated resources are returned to the system. ESRI recomends using the del-statement. But del doesn't delete anything but the name binding to the object. If there are accidently other bindings to the same object nothing will deallocated.