Writing geoprocessing outputs to memory is an alternative to writing output to a geodatabase or file-based format. It is often significantly faster than writing to on-disk formats. Data written to memory is temporary and is deleted when the application is closed. The memory workspace is an ideal location to write intermediate data in a ModelBuilder model or Python script.
Memory-based workspaces
ArcGIS provides two memory-based workspaces where geoprocessing outputs can be written.
memory workspace
The memory workspace is a memory-based workspace that supports output feature classes, tables, and raster datasets.
Use the following ways to write to the memory workspace:
- Select the Memory workspace button
next to a tool output parameter to create a memory workspace path.
- Specify an output dataset path that starts with memory\.
Do not include a file extension in the output name. For example, specify the output as memory\tempOutput.
You can add memory datasets to a map in ArcGIS Pro.
in_memory workspace
Legacy:
The in_memory workspace is the legacy memory-based workspace built for ArcMap that supports output feature classes, tables, and raster datasets.
To write to the in_memory workspace, specify an output dataset path beginning with in_memory\ and with no file extension, for example, in_memory\tempOutput.
A geoprocessing tool cannot add an in_memory output directly to a map. After creating an in_memory output, a tool will create a copy in the project geodatabase. The tool will then add the output from the project geodatabase to the map. To display memory-based data directly in a map, use the memory workspace instead.
Geoprocessing tools will not copy the in_memory output to the project geodatabase under the following conditions:
- The in_memory output is intermediate such as in Python or ModelBuilder workflows.
- The output is not added to an open map when the Add output datasets to an open map geoprocessing option is unchecked, or the Add To Display option is not selected in ModelBuilder.
Unlike the memory workspace, the in_memory workspace does not support subtypes or domains.
Manage the memory workspace
Data in the memory workspace can only be managed using geoprocessing tools and is not shown in the Catalog pane or Catalog view. To see which layers in a map have a memory data source, in the Contents pane, click the List By Data Source button ; memory data sources will be listed under the Memory
workspace.
You can also get a list of datasets in the memory space using ArcPy list functions.
# Set the workspace and list the data saved to memory
arcpy.env.workspace = "memory"
print(f"Memory Feature Classes: {arcpy.ListFeatureClasses()}")
print(f"Memory Rasters: {arcpy.ListRasters()}")
print(f"Memory Tables: {arcpy.ListTables()}")
When using a memory-based workspace, delete any intermediate data as soon as possible to free up system memory resources. The Delete tool can be used to delete data in a memory-based workspace. Delete individual datasets, or the entire workspace, to clear the workspace contents.
Use the memory workspace in Python
Use of memory-based workspaces in Python is only valid for geoprocessing tools. Memory is not a general-purpose virtual directory where files or other data can be written.
Use the memory workspace as shown in the following code sample:
import arcpy
# Set the geoprocessing workspace
arcpy.env.workspace = r"C:\Data\Habitat.gdb"
# Buffer a Roads layer, writing output to memory
arcpy.analysis.Buffer("Roads", r"memory\Buffers", 1000)
# Erase the buffers from a Vegetation layer
arcpy.analysis.Erase("Vegetation", r"memory\Buffers", r"memory\Erased")
# Dissolve the memory output of Erase to make a final output in the gdb workspace
arcpy.management.Dissolve(r"memory\Erased", "FinalOutput")
# Delete any intermediate datasets from memory
arcpy.management.Delete(r"memory\Erased")
arcpy.management.Delete(r"memory\Buffers")
Limitations
Memory-based workspaces have the following limitations:
- Memory-based workspaces do not support geodatabase elements such as feature datasets, relationship classes, attribute rules, contingent values, field groups, spatial or attribute indexes, representations, topologies, geometric networks, or network datasets.
- The Copy tool does not support input or output datasets from a memory-based workspace. To copy datasets in a memory workspace, use the Copy Features or Export Features tool.
- The Truncate Table tool does not support input data from memory-based workspaces.
- Since memory-based workspaces are stored in a system's physical memory (RAM), your system may run low on memory when writing large datasets to the workspace. This can negatively impact processing performance.
- Folders cannot be created in memory-based workspaces.
- Memory workspaces support limited attribute field and schema modifications using Alter Field and other tools. You can modify field aliases but not field names or other properties.