[GIS] Deleting geoprocessing results in ArcGIS without closing mxd file

arcgis-10.1arcpygeoprocessing-framework

I am trying to run a loop of a couple thousand maps in ArcGIS Desktop 10.1 but the program keeps crashing after printing about 100 maps at a time. I read at GeoNet that I need to make sure my results in Results Management are never saved, so I changed my settings accordingly. While this measure allowed the .mxd file to stay a constant size, it didn't resolve the problem of ArcGIS crashing after printing ~100 maps.

In addition, while I'm in a single ArcGIS session, all results still get written to the Current Session in Results. It seems like the reason ArcGIS ultimately crashes is that too much memory is occupied after the results from ~100 maps are memorized.

I just want to run a single ArcGIS session (never closing the .mxd file while the loop is running) because I have thousands of maps to print and I wouldn't like to open and close the same .mxd file and run the same Python script 20-30 times.

Is there a way I can delete the results from the Current Session at the end of each iteration of my for loop?

I was hoping this would prevent ArcGIS from crashing after every 100 maps.

In my Python script, I first read in relevant lists of parameters for my loop from a text file. Then I run my one main for loop. In each iteration, I am saving one buffer .shp and one polygon .shp in a workspace: env.workspace = r"C:\ArcGIS\Mapping Files\All Shapefiles" I then zoom to the buffer layer, export to pdf, and delete the two new layers like so:

for lyr in arcpy.mapping.ListLayers(mxd, "Shape_" + object[i], df):
    arcpy.mapping.RemoveLayer(df, lyr)
for lyr in arcpy.mapping.ListLayers(mxd, "Buffer_" + object[i], df):
    arcpy.mapping.RemoveLayer(df, lyr)
del mxd, df, lyr

Best Answer

If you don't already have this set, I would setup the Geoprocessing Options like so:

GP options

Also, you could always programmatically close the ArcMap document and open it up again. You could do this from python or even a .bat script.

From this GeoNet thread, it appears that you can disable logging via arcpy.gp.logHistory = False but it doesn't appear to have any impact. Unsurprisingly, deleting the metadata from C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.0\ArcToolbox\History has no impact either....

Related Question