I found a serious memory leak when my project run period of hours. Here is the
test code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import logging
import psutil
import time
import _psutil_mswindows
while True:
try:
# # leak
# for process in psutil.process_iter():
# m = process.get_memory_info()
# # leak too
# for pid in psutil.get_pid_list():
# process = psutil.Process(pid)
# m = process.get_memory_info()
# del process
# # not leak
# for pid in psutil.get_pid_list():
# m = _psutil_mswindows.get_process_memory_info(pid)
# leak
for pid in psutil.get_pid_list():
m = _psutil_mswindows.get_process_memory_info_2(pid)
except Exception as ex:
logging.warning(ex)
finally:
time.sleep(0.01)
Run this code and open windows task manager, you will see memory usage of the
process grows rapidly.
Finally I located the problem in _psutil_mswindows.get_process_memory_info_2().
I checked the corresponding C source code and found in _psutil_mswindows.c,
get_process_memory_info_2() calls get_process_info() in process_info.c, and
get_process_info() uses internal pointer "process" and "buffer" as return
value, and get_process_memory_info_2() doesn't free these two pointers.
Maybe using pointer as return value is not a good choice, and all places using
get_process_info() should be checked.
Original issue reported on code.google.com by shajunx...@gmail.com on 22 Sep 2013 at 11:24
Original issue reported on code.google.com by
shajunx...@gmail.com
on 22 Sep 2013 at 11:24