profile/monitor momory use of arcpy script

2915
2
Jump to solution
03-13-2015 07:54 PM
yosukekimura
New Contributor III

Hi,

Is there way to monitor what object takes up how much of memory?  I open lots of things as "in_memory" objects but I want to know if they are reasonable to do so instead loading only part of feature (or raster) to memory.  I also want to know a tool for python generic, since I am making arcpy's Polygons and keep it into list some times, and wondering if that is pushing memory use.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Since this is an Esri site focused on ArcGIS products, I will answer from the ArcPy perspective, which is there are no ArcPy functions or classes that monitor memory usage of ArcPy or Python objects.

The larger or more general question of tracking Python object memory usage has been asked and discussed on many other forums.  An excerpt from the Find out how much memory is being used by an object in Python post that I have always liked is:

There's no easy way to find out the memory size of a python object. One of the problems you may find is that Python objects - like lists and dicts - may have references to other python objects (in this case, what would your size be? The size containing the size of each object or not?). There are some pointers overhead and internal structures related to object types and garbage collection. Finally, some python objects have non-obvious behaviors. For instance, lists reserve space for more objects than they have, most of the time; dicts are even more complicated since they can operate in different ways (they have a different implementation for small number of keys and sometimes they over allocate entries).

Besides the post referenced above, there are numerous other StackOverflow posts on this topic along with links to code for approximating the size of Python objects.  A quick Google search should get you pointed in the right direction.

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

Since this is an Esri site focused on ArcGIS products, I will answer from the ArcPy perspective, which is there are no ArcPy functions or classes that monitor memory usage of ArcPy or Python objects.

The larger or more general question of tracking Python object memory usage has been asked and discussed on many other forums.  An excerpt from the Find out how much memory is being used by an object in Python post that I have always liked is:

There's no easy way to find out the memory size of a python object. One of the problems you may find is that Python objects - like lists and dicts - may have references to other python objects (in this case, what would your size be? The size containing the size of each object or not?). There are some pointers overhead and internal structures related to object types and garbage collection. Finally, some python objects have non-obvious behaviors. For instance, lists reserve space for more objects than they have, most of the time; dicts are even more complicated since they can operate in different ways (they have a different implementation for small number of keys and sometimes they over allocate entries).

Besides the post referenced above, there are numerous other StackOverflow posts on this topic along with links to code for approximating the size of Python objects.  A quick Google search should get you pointed in the right direction.

yosukekimura
New Contributor III

Thank you for pointer.  I got started learning memory_profiler.  I also found that using common sense for saving memory make sense instead of relying on tools too much.

0 Kudos