# Memory Leak in Deepstream parallel branches

**URL:** <https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981>\
**Category:** DeepStream SDK\
**Tags:** deepstream\
**Created:** [July 23, 2025, 11:19am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981 "2025-07-23T11:19:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [July 23, 2025, 11:19am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/1 "2025-07-23T11:19:30Z")

</div>

Please provide complete information as applicable to your setup.

**• Hardware Platform (Jetson / GPU)** dGPU (L4 GPU)  
**• DeepStream Version** 7.0  
**• JetPack Version (valid for Jetson only)**  
**• TensorRT Version** :8.6  
**• NVIDIA GPU Driver Version (valid for GPU only)**:12.2  
**• Issue Type( questions, new requirements, bugs)** BUG  
**• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)** No Idea  
**• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)**

Hi I have the following setup from where I am observing memory leak. The leak is approximately 2 GB per day which increases to 3-4 gb per day when increase in number of sources to 7. I have not tested beyond that yet.  
No of cameras: 4  
No. of parallel branches:2  
I ran my pipeline with below command to get the leak:  
`PYTHONMALLOC=malloc valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --trace-children=yes --log-file=valgrind.log --suppressions=/usr/lib/valgrind/python3.supp python3 main.py --logging --measure_latency`

Uploaded my valgrind log in below drive link.

> **[deepstram\_valgrind\_logs - Google Drive](https://drive.google.com/drive/folders/1Vm4vPhzyvIb7aGPFMrdzMu2v5rKznrlW?usp=sharing)**

Please let me know if anything else is requreed.

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [July 24, 2025, 1:40am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/3 "2025-07-24T01:40:56Z")

</div>

> [@akash.kumar1](#):
>
> python3 main.py --logging --measure\_latency

Thanks for the sharing! is this a custom code? what is the complete media pipeline? can you reprodcue this issue with the latest DS7.1? can you simplify the code to narrow down this issue? for example, if Using one branch or removing some element temporarily, does the issue persist?

---

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [July 24, 2025, 6:11am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/4 "2025-07-24T06:11:28Z")

</div>

_ **is this a custom code?** _  
Yes Fanzh, this is a custom code built using gst and deeepstream plugins only. Plugins are all already available, I did not build any new plugin.

_ **what is the complete media pipeline?** _  
Pipeline diagram I am sharing with you in message (with subject: Pipeline diagarm for memory leak July 23) because we cannot share publicly . I will be happy to share relavent codes via private communications if needed

_ **can you reproduce this issue with the latest DS7.1** _  
I need to migrate my codebase to 7.1, let me see if my team has bandwidth to do so on urgent basis. Will update you on that.

_ **can you simplify the code to narrow down this issue?** _  
I will test with single branch to if issue persists. Can you please review my pipeline diagarm and valgrind log and suggest me the steps to narrow down the issue and reproduce it?  
Valgrind logs are pretty huge and I tried to filter some relavent ones in “valgrind\_definitely\_lost.txt”. Kindly look into once and see if you can point me in right direction.

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [July 25, 2025, 7:54am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/5 "2025-07-25T07:54:40Z")

</div>

1. Notcing you are using new-streammux, what is the resoltuion and fps of the RTSP source? if there are different resolutions, you need to convert to the same resolution with nvvideoconvert plugin because new-streammux does not support scaling. please refer to related doc [heterogeneous-batching](https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_plugin_gst-nvstreammux2.html#heterogeneous-batching).
2. about “The leak is approximately 2 GB per day”, wondering the actual memory usage after running stably, could you share a nvmemstat log by referring to this [topic](https://forums.developer.nvidia.com/t/memory-leak-when-testing-deepstream-sample-app/248227)?
3. after checking the valgrind log, there are some memory leaks in new-streammux, which is opensource. Here is one fix [demux-fix.txt](https://forums.developer.nvidia.com/uploads/short-url/ok4oSmk5WwLeefDxRKZml7pkCcN.txt) (748 Bytes).

---

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [July 28, 2025, 6:23am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/6 "2025-07-28T06:23:06Z")

</div>

Hi @fanzh , I have done following experiments:

1. Tested with single branch and memory leak still persists.
2. Tested with old streammux, still getting memory leak. Added valgrind logs with single branch+old streammux in same drive and “single\_branch\_leak”

Now coming to your suggestions:  
_ **Notcing you are using new-streammux, what is the resoltuion and fps of the RTSP source?** _  
We observed streams with different resolutions causes them to randomly pick one resolution so we have handled that from the source side i.e 1920\*1080. The fps is variable which lies between 25-30 fps. One stream is 60 fps.

_ **about “The leak is approximately 2 GB per day”, wondering the actual memory usage after running stably, could you share a nvmemsta** _  
Let me do that and get back to you.

_ **after checking the valgrind log, there are some memory leaks in new-streammux** _  
Can you please check on this, you have shared fix for demux but you are saying new-streammux.

_ **Regarding migrating to 7.1:** _  
We are migrating our codebase. Will update you once we have tested

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [July 28, 2025, 10:04am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/7 "2025-07-28T10:04:19Z")

</div>

1. noticing there are many “gst\_element\_factory\_create” in single\_branch\_leak-20250728T093744Z-1-001.zip, did you restart pipeline many times? or recreate plugins many times?
2. about “you have shared fix for demux but you are saying new-streammux.”, if you run “export USE\_NEW\_NVSTREAMMUX=yes”, both nvstreammux and nvstreamdexmux will use the new version, which is opensource. the code path is /opt/nvidia/deepstream/deepstream-7.1/sources/gst-plugins/gst-nvmultistream2.

---

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [July 28, 2025, 10:45am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/8 "2025-07-28T10:45:22Z")

</div>

> [@fanzh](#):
>
> - did you restart pipeline many times? or recreate plugins many times?

_ **1. did you restart pipeline many times? or recreate plugins many times?** _  
No fanz, just once. Not sure why this is happenning. Since I am running rtsp feeds, I had added a function to stop the pipeline after some time to add valgrind logs. Maybe because of that.

```auto
def stop_after_hour():
            print("🏁 One hour elapsed: shutting down pipeline")
            #self.pipeline.set_state(Gst.State.NULL)
            
            loop.quit()
            
            return True 
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()
        #bus.add_signal_watch_full()
        bus.connect("message", bus_call, loop)
        
        branch_image_dict = self.branch_for_camera()
        
        for key,value in self.probes_for_metadata.items():
            value["element"].get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, [value["branch_name"]])
           

        self.capsfilter.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, extract_raw_frames, branch_image_dict)
        
        if self.args.measure_latency:
            GLib.timeout_add(1000, perf_data.perf_print_callback)
        GLib.timeout_add(120000, stop_after_hour) #two hrs
        self.pipeline.set_state(Gst.State.PLAYING)
        
        
        Gst.debug_bin_to_dot_file(self.pipeline, Gst.DebugGraphDetails.ALL, "pipeline_graph")
        #self.add_probes()
        try:
            loop.run()
        except:
            pass

        # Cleanup and shutdown when done
        self.pipeline.set_state(Gst.State.NULL)
        #Gst.deinit()

```

1. _ **about “you have shared fix for demux but you are saying new-streammux.”, if you run “export USE\_NEW\_NVSTREAMMUX=yes”, both nvstreammux and nvstreamdexmux will use the new version, which is opensource.** _

Since single branch does not require demux and using old streammux and still facing memory leak, we can safely assume there is another point as well causing leak., sharing piplene diagram for single branch in dm.

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [July 29, 2025, 3:31am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/9 "2025-07-29T03:31:42Z")

</div>

> [@akash.kumar1](#):
>
> stop the pipeline after some time to add valgrind logs.

the pipeline of pipeline\_diagram\_single\_branch is similar to NV sample [deepstream\_test\_3.py](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/tree/master/apps/deepstream-test3) , which supports rtspsrc, nvinfer and tracker. can you use deepstream-test3 to reproduce this memory leak issue. if no, you can compare your custom code with test3, if so, could you provide valgrind and nvmemstat log mentioned above? Thanks!

---

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [July 29, 2025, 3:38am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/10 "2025-07-29T03:38:39Z")

</div>

sure fanzh, let me do that.

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [August 13, 2025, 5:58am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/12 "2025-08-13T05:58:30Z")

</div>

@akash.kumar1 did you try deepstream\_test\_3.py? could you share the test results regarding memory leak? Thanks!

---

<div class="post-metadata">

**Author:** ![akash.kumar1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@akash.kumar1](https://forums.developer.nvidia.com/u/akash.kumar1)\
**Post date:** [August 13, 2025, 6:14am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/13 "2025-08-13T06:14:43Z")

</div>

Hi @fanzh , yes I tried a couple of things and narrowed down the issue. It’s not coming from any deepstream plugins. It is coming when I try to reconnect the streams when eos is reached. I have a custom reconnect logic as following.  
When we recive eos from source-bin we set source to null state and remove it from the pipeline and create a new source bin and link it to the same streammux pad. Have shared my source connection script to you privately. CAn you please take a glance and let me know if you can help us there?

Edit:  
You might siggest nvurisourcebin that have pre-built reconnection logic but, we observed many times it simply fails to reconnect. That’s why we decided to build our custom logic

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [August 18, 2025, 2:26am UTC](https://forums.developer.nvidia.com/t/memory-leak-in-deepstream-parallel-branches/339981/14 "2025-08-18T02:26:04Z")

</div>

> [@akash.kumar1](#):
>
> It’s not coming from any deepstream plugins. It is coming when I try to reconnect the streams when eos is reached.

Thanks for the update! Please open a new topic if having other DeepStream problems.
