# 内存泄漏诊断
# objgraphy
objgraph 是一个用于勘察 Python 内部对象的第三方模块,擅长绘制对象引用关系图以及排查内存泄露问题:
- 取出某种类型的所有实例对象 ( by_type );
- 统计程序中数量最多的对象,并排序 ( show_most_common_types );
- 绘制对象引用关系图 ( show_refs );
- 绘制反向引用关系图 ( show_backrefs );
# 使用
$ pip install objgraph
>>> import objgraph
>>> objgraph.show_most_common_types()
dict 16482
method 8189
function 7095
list 6632
tuple 4797
deque 4670
Event 3112
weakref 2307
AsyncExitStack 1554
RequestResponseCycle 1553
>>> tuples = objgraph.by_type('tuple')
>>> len(tuples)
4425