FYI: arcpy.SelectLayerByLocation_management: Leaks more Memory than Edward Snowden

1105
3
Jump to solution
06-24-2013 12:34 PM
BillMiller
New Contributor
I have a python toolbox (.pyt) that use "SelectLayerByLocation" inside a loop that is called about 50,000 times. It grabs more and more memory after each call to "SelectLayerByLocation". It starts out processing very quickly but then slows down after about 2 hours of processing. The leak can be plugged by removing the code for the "SelectLayerByLocation" but of course that's not very useful.

When I run the same code outside of ARCMAP and without the toolbox then the program does not leak memory at all.  It completes all of the calls to "SelectLayerByLocation" within a reasonable amount of time.

Is there any way to plug this leak?  I would rather use toolbox so that I don't have to write a custom GUI.

arcpy.SelectLayerByLocation_management(inlayer, "INTERSECT", pointGeo, SearchDistance)


Using ArcMap 10.1 SP1 (Build 3143)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
Are you selecting on a layer in your mxd or a different layer? I would recommend not doing this kind of processing on mxd layers as the map will want to catch up with the drawing while it processes in some cases.

View solution in original post

0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
Are you selecting on a layer in your mxd or a different layer? I would recommend not doing this kind of processing on mxd layers as the map will want to catch up with the drawing while it processes in some cases.
0 Kudos
BillMiller
New Contributor
It appears that you are correct. Even if my ArcMap project is empty the datatype should equal "Feature Class" and not "Feature Layer".

I am sort frustrated with the entire process of creating tools using python. There are so many things that can go wrong and most of time it's just forgetting to refresh the TOC. In general the idea seems like a small step in the right direction so hopefully the next generation of GIS folks will not have to suffer as much.

Thank you for taking the time to answer.
0 Kudos
ChrisSnyder
Regular Contributor III
"SelectLayerByLocation" inside a loop that is called about 50,000 times


I have some similar code. I implemented a little trick where if the total selected set gets larger than a certain amount - say 1000 features, I select only the features (SelectByAttribute) that were selected from the last few iterations. The idea being that the SelectByLocation gets slower and slower the more features that are selected. Depending on how many features you have and the spatial arangment of them, it can make add big boost in performace.
0 Kudos