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 issue in "for win in windows:" for MacOs #24

Open
cyberiums opened this issue Apr 17, 2020 · 0 comments
Open

Memory issue in "for win in windows:" for MacOs #24

cyberiums opened this issue Apr 17, 2020 · 0 comments

Comments

@cyberiums
Copy link

I am trying to get top window in MacOS after every click or keyboard activity. But the for loop to go through all windows for finding the active window has memory issues in Quartz.
I made the following test. If you comment the for loop part, memory leak stops.
Any fixes?

from memory_profiler import profile
import sys, time, Quartz
import pygetwindow as gw

def _get_active_window():
    windows = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListExcludeDesktopElements | Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID)
    for win in windows:
        if win['kCGWindowLayer'] == 0:
            return '%s %s' % (win[Quartz.kCGWindowOwnerName], win.get(Quartz.kCGWindowName, ''))


@profile
def main(n):
    for i in range(n):
        _get_active_window()

for i in range(100):
    main(20*i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants