AnsweredAssumed Answered

How to Delete in_memory table

Question asked by jborgion Champion on Dec 7, 2017
Latest reply on Dec 8, 2017 by jborgion

I create a table in memory like this:

temptable = arcpy.CreateTable_management("in_memory","tableinmemory",template)
### house dir is null or street dir is null; item1 & item2 qaqc summary
select = "HouseDir IS NULL OR StreetDir IS NULL"
arcpy.SelectLayerByAttribute_management("view","ADD_TO_SELECTION",select )
if arcpy.Describe("view").FIDSet =='':
elif int(arcpy.Describe("view").FIDSet[0]) >= 1:
    expression = "HouseDir or StreetDir is null"
    outtable = r"C:\Replicas\Replicas.gdb\Errors"


"view" in line 10 is a table view of a feature class created earlier; basically I have on table (view) that is of one schema and I need to copy selected records from it to my 'temptable' which has a different schema. Then I'm able to append records from temptable to an actual table in a real live gdb of the same schema.  This whole piece of code works marvelously, and I repeat several times collecting various data entry errors if they exist. But...


I need to get rid of the tableinmemory, and can't seem to figure out a way to do so. From the python window in ArcMap I run this code:

>>> if arcpy.Exists("in_memory\\tableinmemory"):
...     print "trying to delete"
...     arcpy.Delete_management("tableinmemory")
...     arcpy.Exists("in_memory\\tableinmemory")
trying to delete


But notice after my printed 'trying to delete' there is no indication of TRUE as to whether or not line 4 successfully runs.  However, in the geoprocessing/results I see this warning:

         !WARNING 00010:tableinmemory does not exist


Okay, that's cool.  I guess.  But when I then try to run the code in the top window, I get:

Traceback (most recent call last):
  File "C:\Users\JBorgione\AppData\Local\ESRI\Desktop10.5\AssemblyCache\{7A2884A1-0732-4438-A865-0C69929F369F}\", line 23, in onClick
    temptable = arcpy.CreateTable_management("in_memory","tableinmemory",template)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\", line 17411, in CreateTable
    raise e
ExecuteError: ERROR 000258: Output in_memory\tableinmemory already exists
Failed to execute (CreateTable).


I have another module in which I create a simple polygon feature in memory, and I get rid of it like this:


for lyr in arcpy.mapping.ListLayers(mxd, "", df):
  if == "ExtentPoly":

 I've tried this approach as well for tableinmemory but to no avail.  In fact, in a python window if I try to delete it, it still shows up as an option, even though its gone from the TOC, and I've deleted workspace in_memory:



So how does one really, really, really, delete a table in memory without closing down arcmap?


Having read Joshua Bixby 's  timely series beginning with:  What's in a Name:  When in_memory = In-memory I realize I'm not the first, and probably not the last to find him/herself in this conundrum. (However, I did create a new tag that is a catch all....)