我已经将我的Ubuntu升级到了16.04,并且Python 3.4也升级到了新版本的Python 3.5。为什么Python 3.5使用这么多内存?远远超过Python 3.4
我跑了我的Python代码,我变得麻木了。它使用了比以前多1.5倍的内存。相同的代码!
从下面内存分析器计数上市的对象:
=== Python 3.5 ===============================================
types | # objects | total size
================================= | =========== | ============
<class 'dict | 3526 | 2.93 MB
<class 'str | 24322 | 2.70 MB
<class 'type | 1255 | 1.22 MB
<class 'code | 8240 | 1.13 MB
<class 'tuple | 3257 | 215.20 KB
<class 'set | 566 | 203.81 KB
<class 'list | 1356 | 179.02 KB
<class 'builtin_function_or_method| 2356 | 165.66 KB
<class 'weakref | 2005 | 156.64 KB
<class 'wrapper_descriptor | 1278 | 99.84 KB
<class 'int | 3488 | 96.62 KB
function (__init__) | 650 | 86.33 KB
<class 'method_descriptor | 1212 | 85.22 KB
<class 'getset_descriptor | 1179 | 82.90 KB
<class 'abc.ABCMeta | 70 | 66.92 KB
=== Python 3.4 ===============================================
types | # objects | total size
================================= | =========== | ============
<class 'dict | 2306 | 2.12 MB
<class 'str | 16819 | 1.90 MB
<class 'type | 865 | 824.64 KB
<class 'code | 5586 | 785.75 KB
<class 'set | 390 | 159.81 KB
<class 'tuple | 2206 | 147.46 KB
<class 'builtin_function_or_method| 2170 | 135.62 KB
<class 'weakref | 1444 | 112.81 KB
<class 'list | 717 | 97.89 KB
<class 'wrapper_descriptor | 1220 | 95.31 KB
<class 'int | 2753 | 75.85 KB
<class 'method_descriptor | 1067 | 75.02 KB
<class 'getset_descriptor | 799 | 56.18 KB
function (__init__) | 399 | 52.99 KB
<class 'abc.ABCMeta | 46 | 42.16 KB
==============================================================
我要提醒 - 相同的代码给了这些不同的结果。
为什么发生了?请帮忙。提前致谢。
也许你应该发布代码。 – erip
另请注意,在Python 3.4和3.5中有不同数量的对象。 – erip
您能否生成一个演示内存使用情况相同差异的小示例脚本?鉴于涉及的对象数量,我假设你的真实代码非常大。 – chepner