Skip to content

Viewer: fix per-cycle GL texture leak on stream start/stop (RSDEV-12247) - #15275

Merged
Nir-Az merged 1 commit into
realsenseai:developmentfrom
remibettan:viewer-start-stop-mem-leak
Jun 24, 2026
Merged

Nir-Az merged 1 commit into
realsenseai:developmentfrom
remibettan:viewer-start-stop-mem-leak

Conversation

@remibettan

@remibettan remibettan commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Tracked by: RSDEV-12247

Summary

  • Per-cycle ~3 MB leak on every depth Stop/Start in the viewer (≈50 MB after 20 cycles in soak; >1 GB after 25 in the original repro).
  • Root cause: texture_buffer (common/rendering.h) calls glGenTextures in upload() but has no destructor — every stream Stop, gc_streams destroys+recreates the stream's texture_buffer, leaking the GL texture handle and its driver-side allocation. Rule-of-three violation present since 2017.
  • Fix: add ~texture_buffer { glDeleteTextures } (and zero the handle); delete copy/move (the prior shallow copy ctor would otherwise cause double-free).
  • Secondary: ux_window::_splash_tex is a value-member destroyed after glfwDestroyWindow — now held via unique_ptr and reset in ~ux_window body before the context is torn down, so its glDeleteTextures runs with a valid context.

Numbers (D455, Release, 20× depth-only start/stop, 10s stream + 5s idle)

slope (MB/iter) total delta (MB)
before 2.85 +48
after 0.53 +1

Test

Automated regression test (mem_leak_depth_start_stop) lives in a separate PR: #15277.

Test plan

  • Manual viewer smoke: launch, depth Stop/Start ×10, watch Private Bytes — should stay flat.
  • Manual viewer exit: no GL warnings on shutdown (validates _splash_tex order fix).
  • CI builds the existing viewer + DQT targets cleanly with the deleted copy/move operators.

Comment thread common/ux-window.h Resolved
Comment thread common/ux-window.cpp Resolved

@sysrsbuild-gh-agentic sysrsbuild-gh-agentic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 rs-agentic bot — automated review

Good fix for a long-standing Rule-of-Three violation. The root cause analysis and the OLS-based soak test are solid. Several issues need attention before merge — see inline comments.

Comment thread common/rendering.h Resolved
Comment thread common/ux-window.h Resolved
#include <librealsense2/rs.hpp>

#include <chrono>
#include <fstream>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [rs-agentic bot] ENHANCEMENT — unused <chrono> include

#include <chrono> is included but std::chrono is not used anywhere in this translation unit (timing is delegated to test.sleep()). Remove it to keep the include list clean and avoid potential compile-time slowdown.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied — removed the include. Durations are floats and timing is delegated to test.sleep(), so was indeed unused.

@remibettan
remibettan force-pushed the viewer-start-stop-mem-leak branch from 0449be2 to 165699b Compare June 24, 2026 10:27
Comment thread common/ux-window.cpp Resolved
Comment thread common/ux-window.cpp Resolved
@remibettan
remibettan force-pushed the viewer-start-stop-mem-leak branch from 3738895 to d743fcc Compare June 24, 2026 11:54
Comment thread common/ux-window.cpp Resolved
@Nir-Az
Nir-Az merged commit 335d16d into realsenseai:development Jun 24, 2026
30 checks passed
@remibettan
remibettan deleted the viewer-start-stop-mem-leak branch June 29, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants