Calculating memory fragmentation in Python

烂漫一生 提交于 2021-01-27 06:36:22

问题


I have a long running process that allocates and releases objects constantly. Although objects are being freed, the RSS mem usage goes up over time.

How can I calculate how much fragmentation is happening? One possibility is to calculate RSS / sum_of_allocations and take that as an indicator. even then, how to do I calculate the denominator (sum_of_allocations).


回答1:


Check out the Garbage Collector interface, gc.

http://docs.python.org/2/library/gc.html

You can inspect the objects are being tracked with gc.get_objects()

"As a general rule, instances of atomic types aren’t tracked and instances of non-atomic types (containers, user-defined objects...) are."

There is also gc.garbage, which finds objects that can't be freed but are unreachable.



来源:https://stackoverflow.com/questions/13783983/calculating-memory-fragmentation-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!