Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on windows #432

Closed
giampaolo opened this issue May 23, 2014 · 2 comments
Closed

Memory leak on windows #432

giampaolo opened this issue May 23, 2014 · 2 comments

Comments

@giampaolo
Copy link
Owner

From shajunx...@gmail.com on September 22, 2013 13:24:09

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: http://code.google.com/p/psutil/issues/detail?id=432

@giampaolo
Copy link
Owner Author

From g.rodola on September 22, 2013 05:41:15

This should be a duplicate of issue 413 .

@giampaolo
Copy link
Owner Author

From g.rodola on September 26, 2013 11:46:22

Status: Duplicate
Mergedinto: 413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant