NVIDIA / nvImageCodec

A nvImageCodec library of GPU- and CPU- accelerated codecs featuring a unified interface
https://docs.nvidia.com/cuda/nvimagecodec/index.html
Apache License 2.0
79 stars 5 forks source link

Memory leak when running in thread #22

Open roelmops opened 1 month ago

roelmops commented 1 month ago

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

jantonguirao commented 3 weeks ago

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