我正在尝试理解和调试应用程序中的内存泄漏。
我使用tracemalloc
模块间隔3小时拍摄了2个快照,其中我的应用程序的内存增加了25mb。这是comparison = snapshot2.compare_to(snapshot1, 'filename', cumulative=True)
/usr/lib/python3.6/traceback.py:0: size=2375 KiB (+959 KiB), count=20672 (+8522), average=118 B
/home/ubuntu/foobar/lib/python3.6/linecache.py:0: size=1587 KiB (+709 KiB), count=13895 (+6289), average=117 B
/usr/lib/python3.6/logging/__init__.py:0: size=885 KiB (+672 KiB), count=7767 (+5888), average=117 B
./services/xx_xx_xx.py:0: size=1476 KiB (+311 KiB), count=8350 (+1841), average=181 B
./client/yyyyy.py:0: size=752 KiB (+240 KiB), count=5204 (+1662), average=148 B
./common/cloudwatch.py:0: size=357 KiB (-228 KiB), count=947 (-1631), average=386 B
./controller/api/v1/foo.py:0: size=835 KiB (-221 KiB), count=3713 (-1654), average=230 B
/home/ubuntu/foobar/lib/python3.6/abc.py:0: size=401 KiB (+192 KiB), count=2782 (+685), average=148 B
/usr/lib/python3.6/concurrent/futures/thread.py:0: size=539 KiB (+76.6 KiB), count=1880 (+409), average=293 B
/usr/lib/python3.6/threading.py:0: size=654 KiB (+70.9 KiB), count=1925 (+312), average=348 B
/home/ubuntu/foobar/lib/python3.6/site-packages/requests/sessions.py:0: size=543 KiB (+59.4 KiB), count=2214 (+57), average=251 B
/home/ubuntu/foobar/lib/python3.6/site-packages/botocore/awsrequest.py:0: size=90.5 KiB (+57.1 KiB), count=267 (+212), average=347 B
/home/ubuntu/foobar/lib/python3.6/site-packages/sqlalchemy/engine/result.py:0: size=665 KiB (-51.6 KiB), count=8799 (-726), average=77 B
/usr/lib/python3.6/typing.py:0: size=77.6 KiB (+47.0 KiB), count=475 (+164), average=167 B
/home/ubuntu/foobar/lib/python3.6/site-packages/requests/api.py:0: size=143 KiB (+46.7 KiB), count=394 (+66), average=372 B
/home/ubuntu/foobar/lib/python3.6/_weakrefset.py:0: size=81.6 KiB (+41.5 KiB), count=556 (+148), average=150 B
/home/ubuntu/foobar/lib/python3.6/_collections_abc.py:0: size=60.2 KiB (+38.5 KiB), count=337 (+137), average=183 B
/home/ubuntu/foobar/lib/python3.6/site-packages/sqlalchemy/engine/base.py:0: size=568 KiB (-33.9 KiB), count=6007 (-513), average=97 B
/home/ubuntu/foobar/lib/python3.6/site-packages/botocore/endpoint.py:0: size=234 KiB (+31.6 KiB), count=618 (+90), average=387 B
./services/opex/foobar.py:0: size=129 KiB (+30.5 KiB), count=397 (+78), average=333 B
./client/cczzaa/abcdxyz.py:0: size=63.6 KiB (+25.4 KiB), count=98 (+31), average=664 B
我正在努力从这些数据中得出任何有用的结论。
traceback.py
在这里增长近1mb的情况是什么?有8522个项目,平均大小为111个字节。有谁知道会发生什么?
更奇怪的是,从traceback.py
引用了/usr/lib/python3.6/traceback.py
,而从我的virtualenv /home/ubuntu/foobar/lib/
引用了许多其他内容。
我会在这里提供Python专家的任何指导。