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

Leak of memory #12

Open
Aramis7609 opened this issue Oct 30, 2019 · 1 comment
Open

Leak of memory #12

Aramis7609 opened this issue Oct 30, 2019 · 1 comment

Comments

@Aramis7609
Copy link

After many 'call' to "imagesearch" i got the error message :

pos = imagesearch(nom_xxx, PREC_yyy)
File "......", line nn, in imagesearch
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\core\src\alloc.cpp:72: error: (-4:Insufficient memory) Failed to allocate 14133848 bytes in function 'cv::OutOfMemoryError'

From my point of view, this memory leak is due to opencv cv2.
Then this problem is solved by adding the following lines of Python code in "imagesearch" :

import gc # import the garbage collector, at the beginning
.................... def imagesearch(image, precision=0.8):
....................
....................min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
del img_gray # free memory
del template
del res
gc.collect()
del gc.garbage[:]

Then , there is also about the same problem with "click_image".

@kadusalles
Copy link

del img_gray # free memory
del template
del res
gc.collect()
del gc.garbage[:]

Thank you for this!

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

2 participants