Skip to main content

Rememberme is a handy tool for memory problems in Python.

Project description

Remember Me

Build Status

RememberMe is a handy tool for memory problems in Python. It computes the total memory usage of Python objects.

RememberMe is a replacement for sys.getsizeof

sys.getsizeof is almost confusing in Python:

import sys
a = [1, 2, 3]
b = [a, a, a]
print(sys.getsizeof(a) == sys.getsizeof(b))  # Can you believe the result is `True`?

While rememberme gives you a clear idea how large an object is.

from rememberme import memory
a = [1, 2, 3]
b = [a, a, a]
print(memory(a))  # 172 bytes!
print(memory(b))  # 260 bytes!


pip install rememberme

More features

Check out memory usage in the current frame:

from rememberme import memory
def foo():
    a = [1, 2, 3]
    b = [a, a, a]
    print memory()
foo()  # 260 bytes. Note `a` is included in `b`.

Check out top memory consumers:

from rememberme import top
def foo():
    a = [1, 2, 3]
    b = [a, a, a]
    mem_top = top()  # with no args, check current frame
    print(mem_top[0])  # `b` and its memory usage
    print(mem_top[1])  # `a` and its memory usage

Even pretty print the result!

from rememberme import mem_print
def foo():
    a = [1, 2, 3]
    b = [a, a, a]


                           ┌int (28.0B)
             ┌list (172.0B)┼int (28.0B)
             │             └int (28.0B)
             │             ┌int (28.0B)
list (260.0B)┼list (172.0B)┼int (28.0B)
             │             └int (28.0B)
             │             ┌int (28.0B)
             └list (172.0B)┼int (28.0B)
                           └int (28.0B)

Known issues and limitations

  • For better performance (and making better sense), the global dict, as well as modules, are not included in the memory usage of any objects.
  • We essentially relies on tp_traverse to traverse the object graph. For C extensions, memory usage might be underestimated under various circumstances. For the most common numpy.ndarray, a specific procedure is defined to probe the memory usage correctly, but no correctness is guaranteed for other C extensions, which may have undetectable momery leaks within themselves.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rememberme-0.1.1.tar.gz (66.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page