rememberme是一个在python中处理内存问题的方便工具。
rememberme的Python项目详细描述
记住我
rememberme是一个在python中处理内存问题的方便工具。它计算 python对象。
rememberme是sys.getsizeof
sys.getsizeof
在python中几乎令人困惑:
importsysa=[1,2,3]b=[a,a,a]print(sys.getsizeof(a)==sys.getsizeof(b))# Can you believe the result is `True`?
而rememberme
让您清楚地知道对象有多大。
fromremembermeimportmemorya=[1,2,3]b=[a,a,a]print(memory(a))# 172 bytes!print(memory(b))# 260 bytes!
安装
pip install rememberme
更多功能
查看当前帧中的内存使用情况:
fromremembermeimportmemorydeffoo():a=[1,2,3]b=[a,a,a]printmemory()foo()# 260 bytes. Note `a` is included in `b`.
查看顶级内存消费者:
fromremembermeimporttopdeffoo():a=[1,2,3]b=[a,a,a]mem_top=top()# with no args, check current frameprint(mem_top[0])# `b` and its memory usageprint(mem_top[1])# `a` and its memory usage
甚至漂亮的打印结果!
fromremembermeimportmem_printdeffoo():a=[1,2,3]b=[a,a,a]mem_print(b)foo()
输出:
┌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)
已知问题和限制
- 为了获得更好的性能(和更好的意义),全球dict以及模块, 不包括在任何对象的内存使用中。
- 我们基本上依赖于^{
} 遍历对象图。对于C扩展,在 各种情况。对于最常见的numpy.ndarray
,一个特定的过程被定义为 正确探测内存使用情况,但不能保证其他C扩展的正确性, 它们内部可能有无法检测到的重大泄漏。