ArcGIS provides a system memory-based workspace where output feature classes, tables, and raster datasets can be written—the in_memory workspace. The in_memory workspace is an alternative to writing output to a geodatabase or file-based format like shapefiles or grids, and it is often significantly faster than writing to those formats. Data written to the in_memory workspace is temporary and will be deleted when the application is closed, so it is an ideal location to write intermediate data created in a ModelBuilder model or Python script.
To write to the in-memory workspace, specify an output dataset path beginning with in_memory\ or in_memory/. For example, in_memory\tempOutput or in_memory/tempOutput.
Managing the in_memory workspace
When using the in_memory workspace, any intermediate data should be deleted as soon as possible to free up those system memory resources. The Delete tool can be used to delete data in the in_memory workspace. Individual datasets can be deleted, or the entire workspace can be deleted to clear all the workspace contents.
Using the in_memory workspace in Python
Within a Python script, the in_memory workspace is only valid for geoprocessing tools; it is not a general-purpose virtual directory when you can write any data.
You can use the in_memory workspace as shown in the code sample below.
import arcpy # Set the geoprocessing workspace arcpy.env.workspace = r"C:\Data\Habitat.gdb" # Buffer a Roads layer, writing output to in_memory arcpy.Buffer_analysis("Roads", "in_memory/Buffers", 1000) # Erase the buffers from a Vegetation layer arcpy.Erase_analysis("Vegetation", "in_memory/Buffers", "in_memory/Erased") # Dissolve the in_memory output of Erase to make a final output arcpy.Dissolve_analysis("in_memory/Erased", "FinalOutput")