warpPerspective in python memory leak?
Hi, there,
Each time I call Python API warpPerspective
,
the memory usages are increasing simultaneously.
I suspect that this function does not properly free its memory in Python's garbage collection system.
The following code will eat my entire memory eventually.
It seems that each time rot
have new reference, the old memory did not get free.
My opencv version: 3.0.0-tp compiled on Ubuntu 12.04
I am not familiar with the garbage collection. Is this a bug, or I am doing something wrong here?
def main():
M = np.random.randn(3,3)
img = np.random.randint(255, size=(1024, 1024, 3))
while(1):
rot = cv2.warpPerspective(img, M, (1024, 1024))
time.sleep(1)
Update: I am also use memory_profiler to checkout what happens in my memory.
It seems that the first couple of warpPerspective
do have memory collect.
Their memory increases are zero.
But then after that each time we call warpPerspective
, it increase around 3Mb memory cost.
Line # Mem usage Increment Line Contents
25 55.258 MiB 0.000 MiB @profile
26 def main():
27 55.301 MiB 0.043 MiB M = np.random.randn(3,3)
28 55.301 MiB 0.000 MiB MM = 1024
29 #hp = hpy()
30 79.512 MiB 24.211 MiB court = np.random.randint(255, size=(MM, MM, 3))
31 79.699 MiB 0.188 MiB court = np.random.randint(255, size=(MM, MM, 3))
32 79.879 MiB 0.180 MiB court = np.random.randint(255, size=(MM, MM, 3))
33 104.051 MiB 24.172 MiB court = np.random.randint(255, size=(MM, MM, 3))
34 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
35 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
36 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
37 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
38 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
39 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
40 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
41 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
42 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
43 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
44 104.051 MiB 0.000 MiB court = np.random.randint(255, size=(MM, MM, 3))
45 104.066 MiB 0.016 MiB court = np.uint8(court)
46 108.719 MiB 4.652 MiB rot = cv2.warpPerspective(court, M, (MM, MM))
47 108.773 MiB 0.055 MiB rot = cv2.warpPerspective(court, M, (MM, MM))
48 108.773 MiB 0.000 MiB rot = cv2.warpPerspective(court, M, (MM, MM))
49 108.773 MiB ...
+1 - How did you create that memory usage table?