Memory leak in PyTurboJPEG?
See original GitHub issueHi,
There seems to be a case of unmanaged memory in PyTurboJPEG. Memory is allocated during the image decode process, but not deallocated later (at least not immediately), and the memory usage of the process keeps building up.
As an example, please consider the following code:
from turbojpeg import TurboJPEG, TJPF_GRAY, TJSAMP_GRAY
import psutil
import os
import time
jpeg = TurboJPEG("/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0")
import numpy
i = 0
PROCESS = psutil.Process(os.getpid())
buf = None
with open('some_image.jpg', 'rb') as fin:
buf = fin.read()
for i in range(100):
print 'iteration', i
img_array = jpeg.decode(buf)
print img_array.shape
print 'memory = ', PROCESS.memory_info().rss // 1024
The output of this program looks like this:
...
iteration 43
(2160, 4096, 3)
memory = 806464
iteration 44
(2160, 4096, 3)
memory = 832576
iteration 45
(2160, 4096, 3)
memory = 858472
iteration 46
(2160, 4096, 3)
memory = 884340
iteration 47
(2160, 4096, 3)
memory = 910188
iteration 48
(2160, 4096, 3)
memory = 936316
iteration 49
(2160, 4096, 3)
memory = 962216
iteration 50
...
The memory usage keeps building up till more than a GB. It sometimes goes back to a low value, but again the buildup happens.
The other popular turbojpeg python wrapper – jpeg4py – doesn’t have this problem. However, I prefer using PyTurboJPEG because it offers a scaling factor in the decode function which speeds up things considerably for my use case. But the memory build up is causing problems as I have a tight memory budget.
What could be the reason and are there any known fixes/workarounds?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Yes, the problem has been addressed. Thanks for your support.
The memory growing should be fixed. Please let me know if you still have question. Thank you.