Using in-memory workspace

ArcGIS provides an in-memory workspace where output feature classes and tables can be written. Writing geoprocessing output to the in-memory workspace is an alternative to writing output to a location on disk or a network location. Writing data to the in-memory workspace is often significantly faster than writing to other formats such as a shapefile or geodatabase feature class. However, data written to the in-memory workspace is temporary and will be deleted when the application is closed.

To write to the in-memory workspace, use the path in_memory, as illustrated below.

Saving to in-memory workspace

The following considerations must be made in deciding to write output to the in-memory workspace:

CautionCaution:
  • Data written to the in-memory workspace is temporary and will be deleted when the application is closed.
  • Tables, feature classes, and rasters can be written to the in-memory workspace.
  • The in-memory workspace does not support extended 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.

Managing the in-memory workspace

When data is written to the in-memory workspace, the computer's physical memory (RAM) is consumed. If too much data is written to this workspace, all the computer's memory may be used up and additional data cannot be written to memory. Also, if most or all of the computer's memory is used storing data in this workspace, there may not be sufficient memory to efficiently execute computationally intensive applications such as ArcGIS. In this situation, all tasks in the application may become very slow.

At some point, the computational advantages of using the in-memory workspace are offset by the slowdown of the application. Things that will impact when this point is reached include the other applications running on the system and the starting amount of available physical memory. Avoid using the in-memory workspace if the data to be written is so large that the application will slow down.

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 tables or feature classes can be deleted, or the entire workspace can be deleted to clear all the workspace contents.

In-memory workspace location

A table, feature class, or a raster written to the in-memory workspace will have the source location of GPInMemoryWorkspace, as illustrated below.

In-Memory source location

The long string of characters enclosed in curly brackets {} following GPInMemoryWorkspace is a unique identifier created and used by ArcGIS.

Using in_memory in Python

You can use the in_memory workspace in Python as well, as shown in the code sample below.

import arcpy

table = arcpy.CreateTable_management("in_memory", "table1")
arcpy.AddField_management(table, "Field1", "TEXT", field_length=20)

cursor = arcpy.da.InsertCursor(table, ["Field1"])
cursor.insertRow(["Hello World"])

The in_memory workspace is only valid for geoprocessing tools; it is not a general-purpose virtual directory when you can write any data.

Within your script, use the Delete tool to delete data in the in-memory workspace. Individual tables or feature classes can be deleted, or the entire workspace can be deleted to clear all the workspace contents.

10/29/2012