Skip to content

Instantly share code, notes, and snippets.

@JeremyLG
Created October 6, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremyLG/9db0e8e5dbda6c4a2ee8de24ace16d94 to your computer and use it in GitHub Desktop.
Save JeremyLG/9db0e8e5dbda6c4a2ee8de24ace16d94 to your computer and use it in GitHub Desktop.
Memory usage of python session
import sys
# These are the usual ipython objects, including this one you are creating
ipython_vars = ['In', 'Out', 'exit', 'quit', 'get_ipython', 'ipython_vars']
# Get a sorted list of the objects and their sizes in MB, E6 to E9 for GB
sorted(
[(x, sys.getsizeof(globals().get(x)) / 10E6 * 8)
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 free to join this conversation on GitHub. Already have an account? Sign in to comment