I think cv.fromarray leaks memory (Bug #493)
Description
I'm running on gentoo x64, OpenCV 2.1.
The following code constantly eats memory
from numpy import *
import cv
a = ndarray((400,600,3))
while True:
mat = cv.fromarray(a)
Associated revisions
Merge pull request #493 from pppoe:master
History
Updated by anonymous - over 14 years ago
See also #489
Updated by Daniele Paganelli over 14 years ago
Someway, asking for the objects which reference a
after each fromarray call will stop the memleak.
from numpy import * import cv,gc a = ndarray((400,600,3)) while True: mat = cv.fromarray(a) gc.get_referrers(a)
Updated by Daniele Paganelli over 14 years ago
I'm sorry, it only slows it down, but does not remove the leak.
Updated by Daniele Paganelli over 14 years ago
I think I found the problem.
At the beginning of fromarray(PyObject *o, int allowND), cv.cpp:2790, there is a call to
Is a new python object. Since ao is only used inside the fromarray function, it's fromarray responsibility to free the memory used by ao. A possible solution would be to insert this line befor the return statement (2850): <pre> Py_DECREF(ao); return pythonize_foreign_CvMat(m); </pre> But if for any reason fromarray exits before decreasing the refcount of ao, the memory would be leaken again. I'm totally new to opencv so I don't know which is the best way to solve this problem: insert a decref before each possible function return?
Updated by Daniele Paganelli over 14 years ago
See #499 for a partial solution.
Updated by Diego Abad over 14 years ago
Many thanks!!! this solve mi memory issue
Updated by James Bowman about 14 years ago
Fixed in r4515.
- Status changed from Open to Done
- (deleted custom field) set to fixed