Check memory usage

As with optimizing your workspace, it may also be useful to examine the memory usage of code components. You can do this using Python’s sys.getsizeof method by implementing the following code:

import sys
variables = ['In', 'Out', 'exit', 'quit', 'get_ipython', 'variables'] 

# Get a sorted list of the objects and their sizes
sorted([(x, sys.getsizeof(globals().get(x))) for x in dir() 
     if not x.startswith('_') and x not in sys.modules and x not in ipython_vars], 
     key=lambda x: x[1], reverse=True)

Sign up for more tips