What does “del aprx” at the end of Python code do?

aprxarcgis-proarcpyfor loop

Often times a Python code for ArcGIS Pro requires the statement "del aprx" at the very end, what does this statement do and is it necessary?

I recently ran a Python snippet changing data sources for a list of feature classes. Absentmindedly, I didn't include "del aprx" at the end, and the snippet ran successfully, but program froze afterward.

Could the freeze be related to my omission of "del aprx"?

Best Answer

In Python del means delete the object which would release memory and file locks. So if you saw del abc,bob,x this would mean delete the objects abc, bob and x, what ever they are. aprx is the commonly used name for an ArcGIS Pro project object but the coder could have called it anything like banana, but obviously that's a stupid name for the object it represents.

Without seeing the code and the context the object aprx is used no one can comment other than to say the coder was proactively releasing memory by deleting unwanted objects.