nvImageCodec
nvImageCodec copied to clipboard
Memory leak when running in thread
Version
0.2.0
Describe the bug.
When I instantiate the nvImageCodec encoder for a second time in a thread, memory is not released. Which is more than 1 GB.
Minimum reproducible example
import os
import threading
import time
import numpy as np
import psutil
from nvidia import nvimgcodec
process = psutil.Process(os.getpid())
image_encoder = nvimgcodec.Encoder()
array = (np.random.rand(500, 500, 3) * 255).astype(np.uint8)
nvim = nvimgcodec.as_image(array)
def encode():
image_encoder = nvimgcodec.Encoder()
image_encoder.encode(nvim, "jpeg")
print("Process memory:")
print(f"Before encode in main thread: {process.memory_info().rss / (1024 * 1024):.2f} MB")
encode()
print(f"After encode in main thead: {process.memory_info().rss / (1024 * 1024):.2f} MB")
thread = threading.Thread(target=encode)
thread.start()
thread.join()
print(f"After encode in sub thread: {process.memory_info().rss / (1024 * 1024):.2f} MB")
Environment details
No response
Relevant log output
Process memory: Before encode in main thread: 46.50 MB After encode in main thead: 150.33 MB After encode in sub thread: 1176.45 MB
Other/Misc.
No response
Check for duplicates
- [x] I have searched the open bugs/issues and have found no duplicates for this bug report
This is most likely the same issue as described here: https://github.com/NVIDIA/nvImageCodec/issues/13 It should be fixed on the next release: 0.4.0