2

I am running a Python script to make point feature layer from a series of netCDF files and then perform a spatial join with a number of polygons and save the results as a table. I am using arcpy.MakeNetCDFFeatureLayer_md and address its output to a variable in 'in_memory' workspace. My problem is that even though I am deleting the 'in_memory' after each loop using arcpy.Delete_management('in_memory'), it does not free up my RAM and after a couple of iterations I run into Memory Error. The function that is being called for each netCDF file looks like this:

def spatialJoin(nc):
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = 'in_memory'
    arcpy.MakeNetCDFFeatureLayer_md(nc, "SM", "lon", "lat", "SMPoints", "time;lat;lon", "", "", "", "BY_VALUE")

    <does the spatial join>

    print arcpy.Exists('SMPoints')
    arcpy.Delete_management('SMPoints')
    print arcpy.Exists('SMPoints')

And the console prints:

True
False 

for each iteration, which means Delete_management is working. But checking the python process in windows task manager shows that the data is piling up in RAM! I have tried deleting individual features inside 'in_memory' as well as deleting the whole 'in_memory' but nothing seems to work. Am I missing something here?

P.S. Spatial join does not affect the problem here, problem exists even when I completely comment out the spatial join section.

3
  • It's nasty, but you could try and delete the arcpy module import after each iteration then re import it. Commented Aug 20, 2016 at 0:34
  • 1
    Did you see gis.stackexchange.com/questions/19684/…? Also it's worthwhile to have a look at geeohspatial.blogspot.com.au/2013/12/…
    – fatih_dur
    Commented Aug 20, 2016 at 3:29
  • Thanks @fatih_dur, the second link was useful. I managed to free up the memory by using multiprocessing module. It slowed down the process a bit, but the memory leak has stopped ;)
    – Monobakht
    Commented Aug 20, 2016 at 11:59

1 Answer 1

1

You shouldn't need to set your environment workspace to in_memory as you are doing in your script, so you can drop this line:

arcpy.env.workspace = 'in_memory'

Also, ensure that you are using double-quotes when referencing your in_memory workspace inside of the geoprocessing tool.

arcpy.Delete_management("in_memory")
2
  • 3
    "ensure that you are using double-quotes when referencing your in_memory workspace" - that's a new one for me, can you explain/reference the double-quotes requirement over single-quotes?
    – Midavalo
    Commented Aug 19, 2016 at 21:12
  • Thanks @Radar, but changing to double-quote didn't help!
    – Monobakht
    Commented Aug 20, 2016 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.