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.
- The in_memory workspace does not support geodatabase elements such as subtypes, domains, representations, topologies, geometric networks, and network datasets.
- Feature datasets or folders cannot be created in the in_memory workspace.
- Since the in_memory workspace is stored in your system's physical memory, or RAM, your system may run low on memory if you write large datasets into the workspace. This can negatively impact processing performance.
You cannot display an in_memory dataset on a map. If you run a geoprocessing tool from the Geoprocessing pane or Python window and write the output dataset to in_memory, after processing the output dataset will be copied to the project geodatabase and that geodatabase dataset will be added to the map.
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")