NvBufferDestroy(): memory usage not decreasing


Due to a memory leak issue on L4T 28.1 (https://devtalk.nvidia.com/default/topic/1044597/jetson-tx2/nvvideoencoder-repeated-start-stop-causes-crash-and-memory-leak) we moved our product to L4T 28.2 and modified the multimedia api code with the new features of 28.2 (x4 as we have 4 channels):
MIPI -> DMABUF -> NvBufferTransform() -> Encoder DMABUF -> Encoder capture plane.

In a test I started/stopped all 4 channels in a loop and checked memory usage, which still increases with the number of restarts.

Then I created a simple function which does the following in a loop:

  • Allocates 40 4k buffers (~660 mbytes)
  • Maps the buffers to pointer
  • Syncs the buffers to CPU
  • Writes some dummy data into the buffers
  • Syncs the buffer to device
  • Unmaps the buffers
  • Destroys the buffers
    The result is the same, memory usage (by tegrastats) increases wit every loop iteration.
    I also tried the same code on Jetson with the official L4T.

Test code: https://1drv.ms/u/s!AlsRVJmJKD5JiPZG5ELrSOmtoxmUKA

Am I doing something wrong?
Thanks in advance.

Please apply the prebuilt lib at
[MMAPI]Cannot run NvVideoDecoder in loop/Memory leak in NvVideoEncoder

Hi DaneLLL,

On the Jetson I already replaced libtegrav4l2.so in /usr/lib/aarch64-linux-gnu/tegra with the linked version.
The code I attached seems to have the issue with this library.



Please try

ret_val = NvBufferMemUnMap(dmabuf_fd[i],

It should be &data_ptr[i]. Let’s correct this typo first.

Hi DaneLLL,

The simple test code works correctly now. I will update the library on the real system and give it a try.
I apologize for wasting your time with this stupid mistake.