From 39960936b94f8dd9204cf13638752f63f8ae8a7a Mon Sep 17 00:00:00 2001 From: Pavel Bugneac <50273042+pavelbugneac@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:48:43 +0200 Subject: [PATCH] Remove memory leak caused by ByteTrack There is a memory leak in the official ByteTrack script caused by the `self.removed_stracks` variable which is allowed to grow indefinitely. This issue (&fix) was raised in the ByteTrack repo as well but the devs dont seem to be active anymore and arent reviewing pull requests. The Ultralytics yolov8 repo also had this same bug and together with their devs, we fixed it by adding these two lines which simply keep a fixed length of 100 to the history of removed tracks. This effectively fixes the memory leak without any impact on the accuracy of the tracker. --- .../src/bytetracker/byte_tracker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/mot_analysis/mot_analysis_app/packages/123456789012-MOT_ANALYSIS_CODE-1.0/src/bytetracker/byte_tracker.py b/samples/mot_analysis/mot_analysis_app/packages/123456789012-MOT_ANALYSIS_CODE-1.0/src/bytetracker/byte_tracker.py index 5d39b22..0166e9e 100644 --- a/samples/mot_analysis/mot_analysis_app/packages/123456789012-MOT_ANALYSIS_CODE-1.0/src/bytetracker/byte_tracker.py +++ b/samples/mot_analysis/mot_analysis_app/packages/123456789012-MOT_ANALYSIS_CODE-1.0/src/bytetracker/byte_tracker.py @@ -283,6 +283,8 @@ def update(self, frame_id, output_results): self.lost_stracks.extend(lost_stracks) self.lost_stracks = sub_stracks(self.lost_stracks, self.removed_stracks) self.removed_stracks.extend(removed_stracks) + if len(self.removed_stracks) > 100: + self.removed_stracks = self.removed_stracks[-99:] self.tracked_stracks, self.lost_stracks = remove_duplicate_stracks(self.tracked_stracks, self.lost_stracks) # get scores of lost tracks output_stracks = [track for track in self.tracked_stracks if track.is_activated]