asweigart / asweigart/PyGetWindow
Memory issue in "for win in windows:" for MacOs
- Dominant language
- Python
- Stars
- 422
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
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)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.