You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
From shajunx...@gmail.com on September 22, 2013 13:24:09
Original issue: http://code.google.com/p/psutil/issues/detail?id=432
The text was updated successfully, but these errors were encountered: