Repository navigation
Fix the memory leaks found in the v0.6.0 review - #56
Merged
Merged
Conversation
…-060-PARSE-CACHE]
…nd [MEM-060-EXAMPLE-TASKS]
…DECAR-NOTIFICATIONS]
…talled editor [MEM-060-EXAMPLE-OUTBOX]
…ledgers [MEM-060-DAP-OUTPUT] [MEM-060-UI-LEDGERS]
…M-060-UI-DISPOSE]
…nd it [MEM-060-LOG-SINK]
… [PROF-UI-LIFETIME]
…sitter coverage floor
MelbourneDeveloper
added a commit
that referenced
this pull request
Nov 18, 2026
…stop (#57) This finishes the v0.6.0 leak review. #56 left two items open. ## Fixed - **The .NET forwarder (`lsp-profiler-dotnet/src/cpu.rs`)** was spawned with `drop(tokio::spawn(..))`, which AGENTS.md forbids. Now `SamplerHandle::own_producer` keeps the task's abort handle, and dropping the handle aborts the task. - Before the fix, `sampler_lifetime_tests.rs` failed: the producer outlived its dropped sampler handle (`left: 1, right: 0`). - No `drop(tokio::spawn(` is left in the workspace. - **The Python `stop_tracemalloc` script** left four things behind in the debuggee: the collected cycles in `gc.garbage` (`DEBUG_SAVEALL`), the baseline snapshot, the `atexit` hook and the signal handlers. It now releases all four. - The crate is parked and doesn't build, so the script now lives in `src/memory/scripts/stop_tracemalloc.py`, pulled in with `include_str!`. - A real-interpreter test, `make _python_scripts_test`, runs it as part of `make test`. - Every assertion failed against the old script: 62 objects left in `gc.garbage`, the snapshot still referenced, SIGINT still routed to the profiler, and the exit hook still alive. ## Left as they are These handles end with their owners, so they aren't leaks: - The `pyspy.rs` sampler thread stops when the handle's `Drop` sets the stop flag. - The helper's stop listener ends with the helper process. - `live/scheduler.rs`, `live/watcher.rs` and `cooperative.rs` each end with their consumer. The plan doc records the reasoning for each. ## Verification (Windows 11) `make fmt CHECK=1`, `make lint` and `make test` all pass: 541 Rust tests with every coverage floor met, plus the Python script test and 117 TypeScript tests.
MelbourneDeveloper
added a commit
that referenced
this pull request
Nov 18, 2026
Fixes a LOW item from the v0.6.0 leak review, which #56 wrongly judged bounded. Both decoration maps are keyed by colour, and the palette is re-read from settings on every render, so each palette change left the previous colours' decoration types allocated for the rest of the session. **Test first:** `decoration-palette.test.ts` changes the `lspui.profiler.palette` setting 8 times and paints a hot line after each change. Before the fix it failed with `9 decoration types allocated after 8 palette changes`. **Fix:** a new `pruneToPalette` disposes the types whose colour the current palette no longer uses. It runs whenever a type for a new colour is created, in both the heat and the memory decorations. **Verification:** `npm run lint` passes; the VS Code UI suite (191), the teardown suite (1) and the unit tests (117) pass.
MelbourneDeveloper
added a commit
that referenced
this pull request
Nov 18, 2026
) Fixes the cooperative tail-thread item from the v0.6.0 leak review, which #56 wrongly judged harmless. When the in-process sampler's header arrived after `tail` had already given up, the detached tail thread found no receiver and returned. It never wrote the stop sentinel, so the debuggee kept sampling and appending to a file nobody read, for as long as it ran. **Test first:** `a_header_after_attach_gave_up_stops_the_writer_and_removes_the_file` failed with `the abandoned sample file stays on disk while its writer keeps sampling`. **Fix:** the thread now writes the stop sentinel, waits the usual drain grace so the writer sees it, then removes both files. **Verification:** the `lsp-profiler` lib tests (89) and the cooperative tests pass, clippy is clean, and the spec citations resolve.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes every leak the v0.6.0 static review found. The plan, with one row per fix, is in docs/plans/memory-leak-fixes-0.6.0.md.
Every fix followed fix-bug: a regression test was written first and failed because of the leak, then the fix made it pass. The tests check
Weakcounts, bounded counts of retained entries, or released file handles. None uses RSS, timing orsleep.Fixed
ParseCache16 ended debug sessions still hold their stateonDidTerminateDebugSessionthe progress task still holds the service: 1 transport reference(s) left33 backend sessions alive for 32 open sessions,3 backend sessions alive after stop_allshutdowncall the backend'sstop(.NET heap graphs on disk go too)Serverclones after the session endedTasksowns aJoinSet, aborted at session end, afterquiesceleft: 1, right: 0)in_flight: 32after the guards droppedCancellationHandle::queuereturns an RAIIQueuedRequest1088 unread notifications queued, over the 1024 boundInbound::dropped_notificationsclosed()32 changes queued 32 notifications behind a stalled pumpProfilerUi.dispose()500 timeline points kept for 500 capturesDiagnosticsBus::attach32 ended connections' sinks are still attachedattach_ownedreturns an RAIISinkRegistration49 heapprofile files kept for a bound of 32FileLogSinkdispose()closes the file; two alternating capped filesChecked and not changed
Symbolizer._ids: each CPU session runs its own engine process, so the interner goes with it.cpu.rs): it already ends with a dropped session, becauseSamplerHandle::dropsignals stop. A new test pins that.forgottenqueue and the decoration maps: both are bounded. The queue holds distinct URIs; the maps hold palette colours.lsp-profiler-python: parked, and it does not build in this repo (it needsbasilisk-common). No test can compile against it, so per fix-bug it is unchanged.API changes (minor release)
Inbound::notificationsis a boundedmpsc::Receiver, andInboundgainsdropped_notifications.CancellationHandle::queue/QueuedRequest,DiagnosticsBus::attach_owned/SinkRegistration,MemorySessionManager::stop_all,export::MAX_ARTIFACTS_PER_KINDandexport::ARTIFACT_PREFIX.ProfilerService::shutdownnow also stops memory sessions.FileLogSinkgainsdispose(): Promise<void>and an optional byte cap.Verification (Windows 11, Rust 1.100.0)
make fmt CHECK=1: passmake lint: pass, including the profiler spec-citation gatemake test: pass — 540 Rust tests, 29 .NET tests, 117 TypeScript tests, every coverage floor met (lspkit::treesitter95.77%,lspkit99.20%)