You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ByteTrack Deployment on Deepstream 6.0+ Major Memory Leak #276
I am currently testing the deployment guide of bytetrack in deepstream on a jetson AGX xavier with 8 camera feeds, and it works great apart from the major memory leak. The program uses the entire device memory within 35 minutes of running. If i switch back to nvidia's default trackers no leak occurs.
I have gone through the numerous issues in this repo that attempt to fix the memory leak, such as:
Unfortunately none of the above 'solutions' fix the memory leak. I have ran the deepstream pipeline with valgrind and can verify a leak is occurring, but valgrind does not show exactly where the leak is taking place, it just shows that a pointer is continuously being allocated somewhere in the heap.
I am actively trying to fix this issue, but since i have relatively no experience with the mechanics of bytetrack, i can only do so much besides poking and proding around the codebase until a solution presents itself to me.
Im hoping @ifzhang, @chirag4798 or @callmesora might be able to reply to this issue with some assistance and or insight, otherwise if you are reading this you should just treat this issue as a warning to not deploy or use the deepstream version of bytetrack until this issue has been marked resolved by me or one of the above authors.
@chirag4798
Thanks for your efforts for this bug, but after I modified my code as yours, it runs error as follow, while the not modified version code runs normally. Any advice? ERRROR from element tracker: Failed to submit input to tracker. Error details: gstnvtracker.cpp(610): gst_nv_tracker_submit_input_buffer(): /GstPipeline:test-pipeline/GstNvTracker:tracker
Is anyone able to run it in deepstream after this fix , i am also getting the issue:
ERROR from element tracker: Failed to submit input to tracker. Error details: gstnvtracker.cpp(610): gst_nv_tracker_submit_input_buffer(): /GstPipeline:test-pipeline/GstNvTracker:tracker
Hey guys, I don't have a DeepStream compatible PC/device to test this anymore but here's some hints that might help.
It looks like the memory leak may be caused by the creation of new objects in the processFrame() function. Specifically, in the innermost loop, we are creating new NvMOTTrackedObj objects with the new keyword and storing them in an array, but we are not deleting them anywhere. This means that the memory allocated for these objects will not be freed, resulting in a leak. Additionally, you are creating a new array of NvMOTTrackedObj objects each time the function is called, but you are not freeing any previous instances of the array.
You can try to fix this by using std::vector instead of a raw array and new keyword, so that it will be freed automatically.
Also, you are using std::make_shared to create a new shared_ptr object of BYTETracker, but you are not deleting it anywhere, which can also cause a memory leak.
You can try to fix this by using std::unique_ptr instead of std::shared_ptr.
It's also worth to note that the map byteTrackerMap is not being cleared when the stream is closed, so you might want to clear the map when the stream is closed.
In this implementation, I've replaced the use of raw arrays and the new keyword with std::vector so that the memory is automatically managed. Also, I've replaced the use of std::shared_ptr with std::unique_ptr, which will automatically manage the memory of the BYTETracker objects created.
Also, I've added a removeStream function that erases the streamId of the closed stream from the byteTrackerMap so that it won't cause memory leak in the future.
Activity
Ritesh1991 commentedon Oct 26, 2022
have you found the solution of this issue ?
callmesora commentedon Oct 27, 2022
Sorry I have been busy lately and could not take a look at this.
@chirag4798 is your friend in this situation :D !
Best of luck
Ritesh1991 commentedon Oct 27, 2022
Thanx for Reply,In this repo it hasn't been committed yet, So I need to use chirag's repo to resolve this issue.
kongjibai commentedon Nov 16, 2022
@chirag4798
Thanks for your efforts for this bug, but after I modified my code as yours, it runs error as follow, while the not modified version code runs normally. Any advice?
ERRROR from element tracker: Failed to submit input to tracker. Error details: gstnvtracker.cpp(610): gst_nv_tracker_submit_input_buffer(): /GstPipeline:test-pipeline/GstNvTracker:trackerindraksha commentedon Dec 8, 2022
Is anyone able to run it in deepstream after this fix , i am also getting the issue:
ERROR from element tracker: Failed to submit input to tracker. Error details: gstnvtracker.cpp(610): gst_nv_tracker_submit_input_buffer(): /GstPipeline:test-pipeline/GstNvTracker:tracker
huihui308 commentedon Jan 6, 2023
I have solved byteTracker memory leak on deepstream-6.0
Ritesh1991 commentedon Jan 6, 2023
@huihui308 can you please provide link for it.
callmesora commentedon Jan 15, 2023
Hey guys, I don't have a DeepStream compatible PC/device to test this anymore but here's some hints that might help.
It looks like the memory leak may be caused by the creation of new objects in the processFrame() function. Specifically, in the innermost loop, we are creating new NvMOTTrackedObj objects with the new keyword and storing them in an array, but we are not deleting them anywhere. This means that the memory allocated for these objects will not be freed, resulting in a leak. Additionally, you are creating a new array of NvMOTTrackedObj objects each time the function is called, but you are not freeing any previous instances of the array.
You can try to fix this by using std::vector instead of a raw array and new keyword, so that it will be freed automatically.
Also, you are using std::make_shared to create a new shared_ptr object of BYTETracker, but you are not deleting it anywhere, which can also cause a memory leak.
You can try to fix this by using std::unique_ptr instead of std::shared_ptr.
It's also worth to note that the map byteTrackerMap is not being cleared when the stream is closed, so you might want to clear the map when the stream is closed.
callmesora commentedon Jan 15, 2023
In code (got a little help from ChatGPT but I have no means of testing it so please do )
In this implementation, I've replaced the use of raw arrays and the new keyword with std::vector so that the memory is automatically managed. Also, I've replaced the use of std::shared_ptr with std::unique_ptr, which will automatically manage the memory of the BYTETracker objects created.
Also, I've added a removeStream function that erases the streamId of the closed stream from the byteTrackerMap so that it won't cause memory leak in the future.
sunxirui310 commentedon Mar 18, 2023
std::vector<NvMOTTrackedObj> trackedObjs;seems calls release error
Leon-Cheung-CQ commentedon Jan 15, 2024
Anyone solve this efficiently?