2016-05-14 65 views
0

我已經將我的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 
============================================================== 

我要提醒 - 相同的代碼給了這些不同的結果。

爲什麼發生了?請幫忙。提前致謝。

+1

也許你應該發佈代碼。 – erip

+0

另請注意,在Python 3.4和3.5中有不同數量的對象。 – erip

+0

您能否生成一個演示內存使用情況相同差異的小示例腳本?鑑於涉及的對象數量,我假設你的真實代碼非常大。 – chepner

回答

0

我發現了這個問題。這是pycurl或libcurl庫或兩者中的內存泄漏。我的應用佔用了比以前多出2倍至3倍的內存。

當我將這些庫的新版本替換爲舊版時,應用程序返回到以前的內存使用情況。

但實際上,由於新實現的功能,Python 3.5使用比Python 3.4 + 10%的內存。這是正常的。

謝謝。

+0

我的意思是「純python 3.5」沒有任何進口。 –

相關問題