How to delete a Search Cursor that is never named

Discussion created by dougbrowning on Apr 2, 2018
Latest reply on Apr 2, 2018 by Dan_Patterson

I just want a record count from a Search Cursor.


If I write a line like this

nom = len(list(arcpy.da.SearchCursor(pointLayer, fields, whereClause)))

do I have to worry about deleting the cursor for cleanup?  And if so how?


Or is something like this safer?

with arcpy.da.SearchCursor(pointLayer, fields, whereClause) as cursor:
    denom = len(list(cursor))


Or if I stick the cursor in a function will it release it when the function is done?



Thanks a lot